On Wednesday, May 24, 2017 at 12:05:19 PM UTC-6, Vityou wrote:
> On Tuesday, May 23, 2017 at 8:21:59 PM UTC-6, Matthias Felleisen wrote:
> > Try to start with this: 
> > 
> > 
> > 
> > 
> > 
> > #lang racket ;; new-lang.rkt 
> > 
> > 
> > (provide
> >  #%app
> >  #%datum
> >  #%top-interaction
> >  (rename-out
> >   (new-lambda lambda)
> >   (new-mb     #%module-begin)))
> > 
> > 
> > (define-syntax (new-lambda stx)
> >   (syntax-case stx ()
> >     [(_ (x ...) e ...)
> >      #'(lam '(x ...) '(e ...) (lambda (x ...) e ...))]))
> > 
> > 
> > (struct lam (parameters bodies closure) #:property prop:procedure 2)
> > 
> > 
> > (define-syntax (new-mb stx)
> >   (syntax-case stx ()
> >     [(_ e ...)
> >      #'(#%module-begin
> >         (let ([v e])
> >           (if (lam? v)
> >               `(lambda ,(lam-parameters v) ,@(lam-bodies v))
> >               v))
> >         ...)]))
> > 
> > 
> > 
> > 
> > ;; - - - 
> > 
> > 
> > 
> > #lang s-exp "new-lang.rkt” ;; new-lang-client.rkt 
> > 
> > 
> > ((lambda (x) x)
> >  (lambda (y) y))
> > 
> > 
> > 
> > 
> > 
> > 
> > On May 23, 2017, at 10:03 PM, Vityou <zle...@gmail.com> wrote:
> > 
> > 
> > On Tuesday, May 23, 2017 at 7:17:18 PM UTC-6, Matthias Felleisen wrote:
> > Why do you interpret S-expressions instead of re-mapping lambda and #%app? 
> > 
> > 
> > 
> > 
> > 
> > On May 23, 2017, at 9:14 PM, Vityou <zle...@gmail.com> wrote:
> > 
> > I might be able to do something like this, but what I'm looking for is 
> > something that will be able to show the variables available to it in 
> > adition to its source.  I'll probable have to do something like what you 
> > did with the struct accept add a field with its available variables and 
> > modify #%app to add to its known variables.
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to racket-users...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> > 
> > I dont know what I could map lambda to that would let it retain and print 
> > its known variables besides a list.
> 
> That's probably good enough for most cases, but I tried to add a struct field 
> to record the lexical content, I can't fin a way to mimic evaluating the body 
> of the function in the struct, this is the closest I got:
> 
> (define-syntax (new-app stx)
>   (syntax-case stx ()
>     [(_ f x)
>      #'(let ([result (#%app f x)])
>          (if (lam? result)
>              (struct-copy lam
>                           result
>                           [lex (cons `(,(lam-parameter f) ,(if (lam? x)
>                                                                  `(λ 
> (,(lam-parameter x)) ,(lam-body x))
>                                                                  x))
>                                        (lam-lex f))])
>              result))]))
> 
> It sort of works, but it just blindly tacks on info if the result is a 
> struct.  ((lambda (x) x) (lambda (y) y) results in (function (lambda (y) y) 
> (x (lambda (y) y)))

I was able to get it to work by processing updating the list parts of the 
struct "In parallel" with the normal evaluation by applying the old s-exp 
processing functions to the correct part of the struct:

(define-syntax (new-app stx)
  (syntax-case stx ()
    [(_ f x)
     #'(let ([result (#%app f x)])
         (if (lam? result)
             (struct-copy lam
                          result
                          [lex (third (eval `((λ (,(lam-parameter f)) 
,(lam-body f))
                                                ,(if (lam? x)
                                                     `(λ (,(lam-parameter x)) 
,(lam-body x))
                                                     x))
                                              (lam-lex f)))])
             result))]))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to