kawa-commonlisp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Kawa-commonlisp-dev] tagbodies


From: Jamison Hope
Subject: Re: [Kawa-commonlisp-dev] tagbodies
Date: Fri, 27 Jul 2012 12:14:55 -0400

On Jul 27, 2012, at 11:23 AM, Charles Turner wrote:

On 27 July 2012 13:46, Charles Turner <address@hidden> wrote:
On 27 July 2012 13:02, Charles Turner <address@hidden> wrote:
On 26 July 2012 21:12, Jamison Hope <address@hidden> wrote:
LABELS is very similar to Scheme's letrec, so I would expect the
amount of work to get a working LABELS to be about what you had to do to
make FLET based on LET (i.e. not too much).

Maybe I should just copy the thing in my primitives file and somehow modify it
to to call this method?

Or better just call FLET instead of %let...

I'm struggling to get this working.

I won't quote LETREC, as it's quite large, it can be found in
kawa/lib/prim_syntax.scm

My first idea was to replace (process-binding ..) with (funcall
process-binding ...) in the macro. However, line 122 (of prim_syntax
when replaced like this) throws a (paraphrased)
APPLY - wrong type (kawa.lang.SyntaxForms$SimpleSyntaxForm cannot be
cast to gnu.mapping.procedure) because of the (syntax bindings) bit.
(My FUNCALL is implementing in terms of APPLY).

The next attempt was to use FLET instead. (flet ((process-binding ()
#undefined)) (set! process-binding (lambda (b) ...)) ...). That didn't
work, process-binding just returns #!undefined... Seemed a bit wacky
anyway. I naively thought I could call settingProcedureDecls on
process-binding, but it's compiled into a ModuleMethod so I can't do
that. Am I missing something obvious?

OK, I hadn't noticed how... cleverly, let's say, letrec was implemented
in prim_syntax. Let's just use that as some loose inspiration instead.
Notice that it expands

(letrec ((a a-init)
         (b b-init))
  e ...)

into

(let ((a #!undefined)
      (b #!undefined))
  (set! a a-init)
  (set! b b-init)
  e ...)

So since we now have a working FLET, how about something like this:

(define-syntax labels
  (syntax-rules ()
    ((labels ((fname parameters body ...) ...) e ...)
     (flet ((fname parameters #!void) ...)
       (set! #'fname (lambda parameters body ...)) ...
       e ...))))

Seems to work:

(labels ((e (n) (or (= 0 n) (o (- n 1))))
         (o (n) (not (e n))))
  (e 512))
=> t




-Jamie

--
Jamison Hope
The PTR Group
www.theptrgroup.com






reply via email to

[Prev in Thread] Current Thread [Next in Thread]