Search found 4 matches

by arunbear
Fri Oct 20, 2006 9:35 pm
Forum: Anything else we might add?
Topic: A nifty definition for dictionaries / hashes
Replies: 4
Views: 5584

Hi Lutz, in Perl you can iterate through the (key, value) pairs of a dictionary without loading the whole keyset into memory e.g. my %dict = (name=> 'Aragorn' , alias=> 'Strider'); while(($key, $val) = each %dict) { print "key = $key, value = $val\n"; } Python and Ruby have similar constructs. How c...
by arunbear
Mon Oct 16, 2006 8:46 pm
Forum: Anything else we might add?
Topic: A nifty definition for dictionaries / hashes
Replies: 4
Views: 5584

Here it is as a module: (context 'Dict) (define (Dict:Dict key value) (if value (context (context) key value) (context (context) key))) (define (get key) (Dict key)) (define (put key value) (Dict key value)) (define (keys) (map name (difference (symbols) (cons (sym (string (context)) (context)) '(Di...
by arunbear
Sun Oct 08, 2006 10:19 pm
Forum: Anything else we might add?
Topic: Puzzled by (let examples in the documentation
Replies: 3
Views: 3209

The point is to localise x and y, not a and b. e.g. suppose x and y were created with set rather than let : (define (sum-sq a b) (set 'x (* a a)) (set 'y (* b b)) (+ x y)) (println (sum-sq 3 4)) (println x) (println y) In this case x and y continue to exist outside of the scope they were created in ...
by arunbear
Thu Aug 10, 2006 9:46 pm
Forum: newLISP newS
Topic: This is ridiculous
Replies: 25
Views: 30927

Concerning Perl. Reading the PERL man-page (man perlsub): "The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in...