Changeset 36847 in project


Ignore:
Timestamp:
11/15/18 14:23:13 (4 weeks ago)
Author:
sjamaan
Message:

Update Scheme for Ruby programmers tutorial a bit for CHICKEN 5 (still needs more careful vetting)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/chicken-for-ruby-programmers

    r35290 r36847  
    1515best implemented in an object-oriented fashion, you can choose to use
    1616one of the many object systems.  Have a quick glance at the
    17 [[http://wiki.call-cc.org/chicken-projects/egg-index-4.html#oop|OOP category]] of
     17[[https://wiki.call-cc.org/chicken-projects/egg-index-5.html#oop|OOP category]] of
    1818the egg index to get an impression of the
    1919diversity of styles of object oriented programming you can use with
     
    539539look ''very'' familiar to you.  Here are some examples:
    540540
    541   #;1> (use srfi-1)  ;; Not needed in Ruby
     541  $ chicken-install srfi-1
     542  $ csi
     543  #;1> (import srfi-1)  ;; Not needed in Ruby
    542544  ; loading library srfi-1 ...
    543545  #;2> ;; [1, 2, 3] + [4, 5, 6] / [1, 2, 3].concat([4, 5, 6])
     
    643645ago]]:
    644646
    645   #;1> (use srfi-13) ;; Not needed in Ruby
     647  $ chicken-install srfi-13
     648  $ csi
     649  #;1> (import srfi-13) ;; Not needed in Ruby
    646650  ; loading library srfi-13 ...
    647651  #;2> ;; "abc" + "def"
     
    658662  "this is very cool"
    659663  #;6> ;; "this is very cool".split(" ")
    660   ;; NOT from srfi-13 but chicken's extras unit:
     664  ;; NOT from srfi-13 but chicken's own (chicken string) module:
    661665  (string-split "this is very cool" " ")
    662666  ("this" "is" "very" "cool")
     
    674678CHICKEN:
    675679
    676   #;1> (use regex)
    677   ; loading library regex ...
    678   #;2> (string-search "(.)(.)(\\d+)(\\d)" "THX1138.")
    679   ("HX1138" "H" "X" "113" "8")
    680 
    681 The {{string-search}} procedure automatically transforms
    682 the first string to a regexp.  You can also do that yourself:
    683 
    684   #;3> (string-search (regexp "(.)(.)(\\d+)(\\d)") "THX1138.")
    685   ("HX1138" "H" "X" "113" "8")
     680  #;1> (import (chicken irregex))
     681  ; loading library chicken.irregex ...
     682  #;2> (irregex-search "(.)(.)(\\d+)(\\d)" "THX1138.")
     683  #<regexp-match>
     684  #;3> (irregex-submatch #2 0)
     685  "HX1138"
     686  #;4> (irregex-submatch #2 1)
     687  "H"
     688
     689The {{irregex-search}} procedure automatically transforms
     690the first string to a regexp object.  You can also do that yourself:
     691
     692  #;3> (irregex-search (irregex "(.)(.)(\\d+)(\\d)") "THX1138.")
    686693
    687694The advantage of doing this is that when you need to match several
    688695strings you can use the same regexp so it doesn't have to precompile
    689 the regexp every time you call {{string-search}}.
     696the regexp every time you call {{irregex-search}}.
    690697
    691698=== Hashes
     
    725732For more complex hashing operations, CHICKEN supplies true hash tables.
    726733
    727   #;11> (define h (make-hash-table))
    728   #;12> h
     734  $ chicken-install srfi-69
     735  $ csi
     736  #;1> (import srfi-69)
     737  #;2> (define h (make-hash-table))
     738  #;3> h
    729739  #<hash-table>
    730   #;13> (hash-table-set! h 'foo 12)
     740  #;4> (hash-table-set! h 'foo 12)
    731741  12
    732   #;14> (hash-table-set! h 'bar 101)
     742  #;5> (hash-table-set! h 'bar 101)
    733743  101
    734   #;15> (hash-table-ref h 'bar)
     744  #;6> (hash-table-ref h 'bar)
    735745  101
    736   #;16> (hash-table-delete! h 'bar)
     746  #;7> (hash-table-delete! h 'bar)
    737747  #t
    738   #;17> (hash-table-ref h 'bar)
     748  #;8> (hash-table-ref h 'bar)
    739749  Error: (hash-table-ref) hash-table does not contain key
    740750  bar
     
    744754{{hash-table->alist}}. The {{alist->hash-table}} procedure converts in the
    745755opposite direction. For a complete list of supported procedures, check the
    746 [[/manual/Unit srfi-69|hash table section]] in the manual.
     756[[/eggref/5/srfi-69|hash table]] add-on library docs.
    747757
    748758
     
    770780usually {{#f}} is used:
    771781
    772   #;1> (use srfi-1)
     782  #;1> (import srfi-1)
    773783  ; loading library srfi-1 ...
    774784  #;2> (find even? '(3 1 4 1 5 9))
Note: See TracChangeset for help on using the changeset viewer.