y_nelson 2.3.0 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cd7f6c5aff9cd532358dde6d7f123497771b104
4
- data.tar.gz: f2cc96377dda8a661f3f084092448c5cbc3a0864
3
+ metadata.gz: ff0c7fc0bba7e9f0541b2f3aa811f26242c51627
4
+ data.tar.gz: 9552fe33ca17718ee07307220db945965ad8373e
5
5
  SHA512:
6
- metadata.gz: 502328fd87f19792553fe5fbfc03d14c9d5a05f2f66293cd7ef6d7ccbe5fee43d846cbe003c564e8514865637f8b2639187447170c620c60d376a355ba8b49b8
7
- data.tar.gz: 27e358e98a69d1716ffbbb6b5a25a80397a95e64fee91dccafc906ea9261db9c1a487586784618fca53dcd28efbc82903522e156730cf7fda3a9048df2f9798c
6
+ metadata.gz: 063508644f6eee8b6c3f97289195f003d18c86fcb7a039a0fc73398430eed28d747657dab1b8fa05ae2a036676057d1c387dd65a85dafac7b502870d1e9b5da4
7
+ data.tar.gz: b3a0075c37727b227ee5b8c1f6bdffb8417dad5b67f3b42bceb76b44d3914c64c23bc3df215048b902c347407f5c5905475ba59cd5144f37e5027809a9f127d6
@@ -0,0 +1,6 @@
1
+ This document serves to acknowledge the support of Bioinformatics Program,
2
+ Taiwan International Graduate Program, Institute of Computer Science,
3
+ Academia Sinica (128, Academia Road, Sec. 2. Namkang, Taipei, 115), and
4
+ of Bioinformatics Institute, National Yang-Ming University, Taipei,
5
+ Taiwan. Without their support, creation of this package would not be
6
+ possible.
@@ -241,6 +241,39 @@ defined? Gamma
241
241
  Code lines and comments
242
242
  \end_layout
243
243
 
244
+ \begin_layout Standard
245
+ Comments are denoted by
246
+ \family typewriter
247
+ #
248
+ \family default
249
+ sign.
250
+ Anything on the line following the
251
+ \family typewriter
252
+ #
253
+ \family default
254
+ sign is ignored:
255
+ \end_layout
256
+
257
+ \begin_layout LyX-Code
258
+ puts
259
+ \begin_inset Quotes eld
260
+ \end_inset
261
+
262
+ Hello world!
263
+ \begin_inset Quotes erd
264
+ \end_inset
265
+
266
+ # this line prints the words
267
+ \begin_inset Quotes eld
268
+ \end_inset
269
+
270
+ Hello world!
271
+ \begin_inset Quotes erd
272
+ \end_inset
273
+
274
+
275
+ \end_layout
276
+
244
277
  \begin_layout Standard
245
278
  Ruby lines can be written with or without semicolons:
246
279
  \end_layout
@@ -267,7 +300,7 @@ a =
267
300
  \begin_inset Quotes eld
268
301
  \end_inset
269
302
 
270
- Hello
303
+ Hello
271
304
  \begin_inset Quotes eld
272
305
  \end_inset
273
306
 
@@ -279,40 +312,7 @@ world!
279
312
  \begin_inset Quotes erd
280
313
  \end_inset
281
314
 
282
- ; puts a + b
283
- \end_layout
284
-
285
- \begin_layout Standard
286
- Comments are denoted by
287
- \family typewriter
288
- #
289
- \family default
290
- sign.
291
- Anything on the line following the
292
- \family typewriter
293
- #
294
- \family default
295
- sign is ignored:
296
- \end_layout
297
-
298
- \begin_layout LyX-Code
299
- puts
300
- \begin_inset Quotes eld
301
- \end_inset
302
-
303
- Hello world!
304
- \begin_inset Quotes erd
305
- \end_inset
306
-
307
- # this line prints the words
308
- \begin_inset Quotes eld
309
- \end_inset
310
-
311
- Hello world!
312
- \begin_inset Quotes erd
313
- \end_inset
314
-
315
-
315
+ ; puts a + ' ' + b
316
316
  \end_layout
317
317
 
318
318
  \begin_layout Part*
@@ -1418,7 +1418,7 @@ def average( a, b, c
1418
1418
  \color red
1419
1419
  =
1420
1420
  \color inherit
1421
- :spot )
1421
+ nil )
1422
1422
  \end_layout
1423
1423
 
1424
1424
  \begin_layout LyX-Code
@@ -1426,11 +1426,7 @@ def average( a, b, c
1426
1426
  \color red
1427
1427
  #
1428
1428
  \color inherit
1429
- If c argument was not given, :spot symbol will be assigned
1430
- \end_layout
1431
-
1432
- \begin_layout LyX-Code
1433
- # to c by default.
1429
+ If c argument was not given, it will default to nil
1434
1430
  \end_layout
1435
1431
 
1436
1432
  \begin_layout LyX-Code
@@ -1442,11 +1438,9 @@ if
1442
1438
  \color red
1443
1439
  ==
1444
1440
  \color inherit
1445
- :spot
1441
+ nil
1446
1442
  \color red
1447
1443
  then
1448
- \color inherit
1449
- # only 2 arguments were supplied
1450
1444
  \end_layout
1451
1445
 
1452
1446
  \begin_layout LyX-Code
@@ -1457,8 +1451,6 @@ then
1457
1451
 
1458
1452
  \color red
1459
1453
  else
1460
- \color inherit
1461
- # 3 arguments were supplied
1462
1454
  \end_layout
1463
1455
 
1464
1456
  \begin_layout LyX-Code
@@ -1679,7 +1671,7 @@ examine_arguments( 1 )
1679
1671
  \end_layout
1680
1672
 
1681
1673
  \begin_layout LyX-Code
1682
- examine_arguments( :hello, :spot, 3, 5, "garbage" )
1674
+ examine_arguments( :hello, nil, 3, 5, "garbage" )
1683
1675
  \end_layout
1684
1676
 
1685
1677
  \begin_layout LyX-Code
@@ -1776,11 +1768,11 @@ as hash pairs in the method call
1776
1768
  \end_layout
1777
1769
 
1778
1770
  \begin_layout LyX-Code
1779
- def density( length: 1, width: 1, height: 1, weight: 1 )
1771
+ def density( x: 1, y: 1, z: 1, weight: 1 )
1780
1772
  \end_layout
1781
1773
 
1782
1774
  \begin_layout LyX-Code
1783
- weight.to_f / ( length * width * height )
1775
+ weight.to_f / ( x * y * z )
1784
1776
  \end_layout
1785
1777
 
1786
1778
  \begin_layout LyX-Code
@@ -1792,7 +1784,7 @@ end
1792
1784
  \end_layout
1793
1785
 
1794
1786
  \begin_layout LyX-Code
1795
- density( length: 2, width: 2, height: 2, weight: 10 )
1787
+ density( x: 2, y: 2, z: 2, weight: 10 )
1796
1788
  \end_layout
1797
1789
 
1798
1790
  \begin_layout LyX-Code
@@ -1826,7 +1818,7 @@ dens_closure =
1826
1818
  \end_layout
1827
1819
 
1828
1820
  \begin_layout LyX-Code
1829
- nn[:weight].to_f / ( nn[:length] * nn[:width] * nn[:height] ) end
1821
+ nn[:weight].to_f / ( nn[:x] * nn[:y] * nn[:z] ) end
1830
1822
  \end_layout
1831
1823
 
1832
1824
  \begin_layout LyX-Code
@@ -1834,7 +1826,7 @@ dens_closure =
1834
1826
  \end_layout
1835
1827
 
1836
1828
  \begin_layout LyX-Code
1837
- dens_closure.( length: 2, width: 2, height: 2, weight: 10 )
1829
+ dens_closure.( x: 2, y: 2, z: 2, weight: 10 )
1838
1830
  \end_layout
1839
1831
 
1840
1832
  \begin_layout LyX-Code
@@ -1872,11 +1864,11 @@ In more complicated method argument structures, it can be advantageous to
1872
1864
  \end_layout
1873
1865
 
1874
1866
  \begin_layout LyX-Code
1875
- h = { length: 2, width: 3, height: 4 }
1867
+ h = { x: 2, y: 3, z: 4 }
1876
1868
  \end_layout
1877
1869
 
1878
1870
  \begin_layout LyX-Code
1879
- #=> {:length=>2, :width=>3, :height=>4}
1871
+ #=> {:x=>2, :y=>3, :z=>4}
1880
1872
  \end_layout
1881
1873
 
1882
1874
  \begin_layout LyX-Code
@@ -1912,11 +1904,11 @@ a0.class
1912
1904
  \end_layout
1913
1905
 
1914
1906
  \begin_layout LyX-Code
1915
- a1 = [ 1, 2, 3, length: 2, width: 3, height: 4 ]
1907
+ a1 = [ 1, 2, 3, x: 2, y: 3, z: 4 ]
1916
1908
  \end_layout
1917
1909
 
1918
1910
  \begin_layout LyX-Code
1919
- #=> [1, 2, 3, {:length=>2, :width=>3, :height=>4}]
1911
+ #=> [1, 2, 3, {:x=>2, :y=>3, :z=>4}]
1920
1912
  \end_layout
1921
1913
 
1922
1914
  \begin_layout LyX-Code
@@ -1940,19 +1932,19 @@ a1[-1]
1940
1932
  \end_layout
1941
1933
 
1942
1934
  \begin_layout LyX-Code
1943
- #=> {:length=>2, :width=>3, :height=>4}
1935
+ #=> {:x=>2, :y=>3, :z=>4}
1944
1936
  \end_layout
1945
1937
 
1946
1938
  \begin_layout Standard
1947
1939
  In other words, if there are any trailing
1948
1940
  \family typewriter
1949
- key / value
1941
+ key/value
1950
1942
  \family default
1951
1943
  pairs inside square brackets, they will be collected into a hash, which
1952
1944
  will become the last element of the array.
1953
1945
  This possibility to mix ordered elements with
1954
1946
  \family typewriter
1955
- key / value
1947
+ key/value
1956
1948
  \family default
1957
1949
  pairs is used eg.
1958
1950
  in
@@ -2022,7 +2014,7 @@ doubler.arity
2022
2014
  \end_layout
2023
2015
 
2024
2016
  \begin_layout LyX-Code
2025
- adder = lambda { |p, q| p + q }
2017
+ adder = -> p, q { p + q }
2026
2018
  \end_layout
2027
2019
 
2028
2020
  \begin_layout LyX-Code
@@ -2046,7 +2038,7 @@ adder.arity
2046
2038
  \end_layout
2047
2039
 
2048
2040
  \begin_layout LyX-Code
2049
- scaler = lambda { |number, p, q| number * (q / p) }
2041
+ scaler = -> number, p, q { number * ( q.to_f / p ) }
2050
2042
  \end_layout
2051
2043
 
2052
2044
  \begin_layout LyX-Code
@@ -2058,7 +2050,7 @@ scaler.call( 10, 2, 3 )
2058
2050
  \end_layout
2059
2051
 
2060
2052
  \begin_layout LyX-Code
2061
- #=> 15
2053
+ #=> 15.0
2062
2054
  \end_layout
2063
2055
 
2064
2056
  \begin_layout LyX-Code
@@ -2070,7 +2062,7 @@ scaler.arity
2070
2062
  \end_layout
2071
2063
 
2072
2064
  \begin_layout LyX-Code
2073
- constant_function = lambda { 42 }
2065
+ constant_function = -> { 42 }
2074
2066
  \end_layout
2075
2067
 
2076
2068
  \begin_layout LyX-Code
@@ -2099,7 +2091,7 @@ Closures / methods with variable length arguments indicate this by reporting
2099
2091
  \end_layout
2100
2092
 
2101
2093
  \begin_layout LyX-Code
2102
- summation = lambda { |*array| array.reduce( :+ ) }
2094
+ summation = -> *array { array.reduce( :+ ) }
2103
2095
  \end_layout
2104
2096
 
2105
2097
  \begin_layout LyX-Code
@@ -2123,7 +2115,7 @@ summation.arity
2123
2115
  \end_layout
2124
2116
 
2125
2117
  \begin_layout LyX-Code
2126
- array_scale = lambda { |*a, coeff| a.map { |e| e * coeff } }
2118
+ array_scale = -> *a, coeff { a.map { |e| e * coeff } }
2127
2119
  \end_layout
2128
2120
 
2129
2121
  \begin_layout LyX-Code
@@ -2151,13 +2143,13 @@ Return value
2151
2143
  \end_layout
2152
2144
 
2153
2145
  \begin_layout Standard
2154
- The last statement in a closure / method becomes the return value.
2146
+ The last statement in a closure or method becomes the return value.
2155
2147
  In methods and lambda-type closures, return statement can also be used
2156
2148
  explicitly:
2157
2149
  \end_layout
2158
2150
 
2159
2151
  \begin_layout LyX-Code
2160
- divider = lambda { |u, v|
2152
+ divider = -> u, v {
2161
2153
  \end_layout
2162
2154
 
2163
2155
  \begin_layout LyX-Code
@@ -2165,7 +2157,7 @@ divider = lambda { |u, v|
2165
2157
  \end_layout
2166
2158
 
2167
2159
  \begin_layout LyX-Code
2168
- return :division_by_zero # explicit return statement
2160
+ return :division_by_zero # explicit return
2169
2161
  \end_layout
2170
2162
 
2171
2163
  \begin_layout LyX-Code
@@ -2173,7 +2165,7 @@ divider = lambda { |u, v|
2173
2165
  \end_layout
2174
2166
 
2175
2167
  \begin_layout LyX-Code
2176
- u / v # implicit return value - last statement of the closure
2168
+ u.to_f / v # implicit return - last statement
2177
2169
  \end_layout
2178
2170
 
2179
2171
  \begin_layout LyX-Code
@@ -2189,7 +2181,7 @@ divider.call( 15, 3 )
2189
2181
  \end_layout
2190
2182
 
2191
2183
  \begin_layout LyX-Code
2192
- #=> 5
2184
+ #=> 5.0
2193
2185
  \end_layout
2194
2186
 
2195
2187
  \begin_layout LyX-Code
@@ -2205,19 +2197,15 @@ experimental_closure = proc {
2205
2197
  \end_layout
2206
2198
 
2207
2199
  \begin_layout LyX-Code
2208
- 1 # this value will be ignored
2200
+ 42 # ignored
2209
2201
  \end_layout
2210
2202
 
2211
2203
  \begin_layout LyX-Code
2212
- 3 # this value will be ignored, too
2204
+ 41 # returned
2213
2205
  \end_layout
2214
2206
 
2215
2207
  \begin_layout LyX-Code
2216
- 42 # this value will be discarded as well
2217
- \end_layout
2218
-
2219
- \begin_layout LyX-Code
2220
- 41 } # this value will be returned
2208
+ }
2221
2209
  \end_layout
2222
2210
 
2223
2211
  \begin_layout LyX-Code
@@ -2237,15 +2225,15 @@ experimental_lambda = lambda {
2237
2225
  \end_layout
2238
2226
 
2239
2227
  \begin_layout LyX-Code
2240
- 1 # this value will be ignored
2228
+ 1 # ignored
2241
2229
  \end_layout
2242
2230
 
2243
2231
  \begin_layout LyX-Code
2244
- return 3 # this value will be returned
2232
+ return 3 # returned
2245
2233
  \end_layout
2246
2234
 
2247
2235
  \begin_layout LyX-Code
2248
- 7 # execution will never get here at all
2236
+ 7 # never executed
2249
2237
  \end_layout
2250
2238
 
2251
2239
  \begin_layout LyX-Code
@@ -2290,15 +2278,11 @@ YPetri
2290
2278
  \end_layout
2291
2279
 
2292
2280
  \begin_layout LyX-Code
2293
- multiplication_table = lambda { |number|
2281
+ mult_table = -> number {
2294
2282
  \end_layout
2295
2283
 
2296
2284
  \begin_layout LyX-Code
2297
- [1, 2, 3, 4, 5]
2298
- \end_layout
2299
-
2300
- \begin_layout LyX-Code
2301
- .map { |element| element * number }
2285
+ [1, 2, 3, 4, 5].map { |e| e * number }
2302
2286
  \end_layout
2303
2287
 
2304
2288
  \begin_layout LyX-Code
@@ -2310,13 +2294,12 @@ multiplication_table = lambda { |number|
2310
2294
  \end_layout
2311
2295
 
2312
2296
  \begin_layout Standard
2313
- This method returns 5 values.
2297
+ This closure returns 5 values.
2314
2298
  We can receive them by using a simultaneous assignment statement:
2315
2299
  \end_layout
2316
2300
 
2317
2301
  \begin_layout LyX-Code
2318
- by_one, by_two, by_three, by_four, by_five = multiplication_table.call( 7
2319
- )
2302
+ by_one, by_two, by_three, by_four, by_five = mult_table.call( 7 )
2320
2303
  \end_layout
2321
2304
 
2322
2305
  \begin_layout LyX-Code
@@ -2352,7 +2335,7 @@ Or we can simply collect them in an array:
2352
2335
  \end_layout
2353
2336
 
2354
2337
  \begin_layout LyX-Code
2355
- collection = multiplication_table.( 3 )
2338
+ collection = mult_table.( 3 )
2356
2339
  \end_layout
2357
2340
 
2358
2341
  \begin_layout LyX-Code
@@ -2371,7 +2354,7 @@ YNelson
2371
2354
  \end_layout
2372
2355
 
2373
2356
  \begin_layout LyX-Code
2374
- constant_vector = lambda { return 1, 2, 3 }
2357
+ constant_vector = -> { return 1, 2, 3 }
2375
2358
  \end_layout
2376
2359
 
2377
2360
  \begin_layout LyX-Code
@@ -2572,7 +2555,11 @@ name
2572
2555
  Car
2573
2556
  \family default
2574
2557
  ".
2575
- This standard behavior is termed constant magic.
2558
+ This standard behavior is termed
2559
+ \emph on
2560
+ constant magic
2561
+ \emph default
2562
+ .
2576
2563
 
2577
2564
  \family typewriter
2578
2565
  NameMagic
@@ -2623,8 +2610,8 @@ NaCl.name
2623
2610
  \end_layout
2624
2611
 
2625
2612
  \begin_layout Standard
2626
- It might seem like a small thing, but in a big file of complicated equation,
2627
- it really starts to matter whether one writes on each line "
2613
+ It might seem like a small thing, but in a big file full of complicated
2614
+ statements, it really matters whether you have to write each time "
2628
2615
  \family typewriter
2629
2616
  NaCl = Chemical.new( name: NaCl )
2630
2617
  \family default
@@ -3020,6 +3007,31 @@ John = Londoner.new
3020
3007
  John.class.settlement #=> London
3021
3008
  \end_layout
3022
3009
 
3010
+ \begin_layout Standard
3011
+ To make it easier to ask humans about their settlement, let's reopen class
3012
+
3013
+ \family typewriter
3014
+ Human
3015
+ \family default
3016
+ and delegate method
3017
+ \family typewriter
3018
+ #settlement
3019
+ \family default
3020
+ to the class:
3021
+ \end_layout
3022
+
3023
+ \begin_layout LyX-Code
3024
+ class Human
3025
+ \end_layout
3026
+
3027
+ \begin_layout LyX-Code
3028
+ def settlement; self.class.settlement end
3029
+ \end_layout
3030
+
3031
+ \begin_layout LyX-Code
3032
+ end
3033
+ \end_layout
3034
+
3023
3035
  \begin_layout Standard
3024
3036
  Alternative syntax for subclassing is this:
3025
3037
  \end_layout
@@ -3189,16 +3201,32 @@ Convenience methods are methods in which the consistency of the behavior
3189
3201
  is traded for syntax sweetness.
3190
3202
  Convenience methods may do entirely different things for different argument
3191
3203
  sets.
3192
- For example,
3204
+ For example, in
3205
+ \family typewriter
3206
+ YPetri
3207
+ \family default
3208
+ , (a Petri net gem on which
3209
+ \family typewriter
3210
+ YNelson
3211
+ \family default
3212
+ depends, you can install it by "
3213
+ \family typewriter
3214
+ gem install y_petri
3215
+ \family default
3216
+ ", if you haven't done so yet),
3193
3217
  \family typewriter
3194
3218
  Place#marking
3195
3219
  \family default
3196
3220
  without arguments simply returns the place's marking.
3197
- But with arguments, it can be used to define a guard.
3221
+ But with arguments, it can be used to define a guard:
3222
+ \end_layout
3223
+
3224
+ \begin_layout LyX-Code
3225
+ require 'y_petri' and include YPetri
3198
3226
  \end_layout
3199
3227
 
3200
3228
  \begin_layout LyX-Code
3201
- A = Place.new marking: 42
3229
+ A = Place marking: 42
3202
3230
  \end_layout
3203
3231
 
3204
3232
  \begin_layout LyX-Code
@@ -3214,12 +3242,20 @@ A.marking # Simply returns its marking
3214
3242
  \end_layout
3215
3243
 
3216
3244
  \begin_layout LyX-Code
3217
- A.marking "must never be negative" do |m| m >= 0 end
3245
+ A.marking "must never be above 100" do |m| m <= 100 end
3246
+ \end_layout
3247
+
3248
+ \begin_layout LyX-Code
3249
+ A.marking = 99 # no problem
3250
+ \end_layout
3251
+
3252
+ \begin_layout LyX-Code
3253
+ A.marking = 101 # YPetri::GuardError is raised
3218
3254
  \end_layout
3219
3255
 
3220
3256
  \begin_layout Standard
3221
- Depending on circumstances, use of convenience methods in reusable code
3222
- may or may not be bad practice.
3257
+ Convenience methods are especially suited for non-reusable code, but their
3258
+ use may sometimes be efficient also in reusable code.
3223
3259
  \end_layout
3224
3260
 
3225
3261
  \begin_layout LyX-Code