[squeak-dev] Re: [Question] nil, true, false in array literals

Stéphane Rollandin lecteur at zogotounga.net
Fri Dec 5 19:41:03 UTC 2008


>> prog := #(funcall (lambda (x) (sqrt x)) 5) asCons
> 
> and then you do something like this
> (anArray at:1) perform: ((anArray at:2) at:1) ? :)

no, the #asCons part convert the array into a cons cell.

the actual usage is in methods like ULisp class>>#amb where Lisp code 
can be written directly in Smalltalk:

==========================

amb

	^#(in-library amb

(define amb-fail `*)

(define initialize-amb-fail
   (lambda ()
     (set! amb-fail
       (lambda ()
         (error 'amb tree exhausted')))))

(initialize-amb-fail)

(define-macro amb
   (lambda #'alts...'
     `(let ((#'+prev-amb-fail' amb-fail))
        (call/cc
         (lambda (#'+sk')
           ,@(map (lambda (alt)
                    `(call/cc
                      (lambda (#'+fk')
                        (set! amb-fail
                          (lambda ()
                            (set! amb-fail #'+prev-amb-fail')
                            (#'+fk' `fail)))
                        (#'+sk' ,alt))))
			#'alts...')
           (#'+prev-amb-fail'))))))

(define assert
   (lambda (pred)
     (if (not pred) (amb))))

(define-macro bag-of
   (lambda (e)
     `(let ((#'+prev-amb-fail' amb-fail)
            (#'+results' `()))
        (if (call/cc
             (lambda (#'+k')
               (set! amb-fail (lambda () (#'+k' false)))
               (let ((#'+v' ,e))
                 (set! #'+results' (cons #'+v' #'+results'))
                 (#'+k' true))))
            (amb-fail))
        (set! amb-fail #'+prev-amb-fail')
        (reverse! #'+results'))))
	)

===============================================


... so this goes a little beyond the fast dirty hack thing :)


there is much more in LispKit, here is the link again:
http://www.zogotounga.net/comp/squeak/lispkit.htm


Stef





More information about the Squeak-dev mailing list