On Thursday, May 25, 2017 at 5:50:29 PM UTC-6, Matthias Felleisen wrote: > The client module can refer to all imported #% forms. If you don’t export it > from the language module, it’s not there. [Well, mostly] Implicitly the > client module already refers to #% forms already. > > > > > On May 25, 2017, at 7:09 PM, Vityou <zlee...@gmail.com> wrote: > > > > On Wednesday, May 24, 2017 at 2:05:23 PM UTC-6, Matthias Felleisen wrote: > >> Don’t eval. This is a bit crude but it now your lam-s keep track of your > >> environment, too. > >> > >> #lang racket ;; new-lang.rkt > >> > >> (provide > >> #%app > >> #%datum > >> #%top-interaction > >> (rename-out > >> (new-lambda lambda) > >> (new-mb #%module-begin))) > >> > >> (require racket/stxparam) > >> > >> (define-syntax (new-lambda stx) > >> (syntax-case stx () > >> [(_ (x ...) e ...) > >> #`(letrec ([L (lam '(x ...) > >> '(e ...) > >> (*env) > >> (lambda (x ...) > >> (syntax-parameterize ([*env > >> (lambda (stx) > >> (syntax-case stx () > >> [(_) #`(append '(x > >> ...) (lam-environment L))]))]) > >> e) > >> ...))]) > >> L)])) > >> (define-syntax-parameter *env > >> (syntax-rules () [(_) '()])) > >> (struct lam (parameters bodies environment closure) #:property > >> prop:procedure 3) > >> > >> (define-syntax (new-mb stx) > >> (syntax-case stx () > >> [(_ e ...) > >> #'(#%module-begin > >> (let ([v e]) > >> (if (lam? v) > >> `(let (,@(map (lambda (x) `(,x --some-value--)) > >> (lam-environment v))) > >> (lambda ,(lam-parameters v) ,@(lam-bodies v))) > >> v)) > >> ...)])) > >> > >> > >> > >>> On May 24, 2017, at 3:41 PM, Vityou <zlee...@gmail.com> wrote: > >>> > >>> 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))])) > > > > Thanks that works great, I just changed (append '(x) (lam-environment L)) > > to (cons `(x ,x) (lam-environment L)) to get the actual value. And this is > > unrelated but is there a way to restrict the user of the lambda-calculus > > language from using the exported #%... macros? > > > > -- > > 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.
I was looking at some different lambda calculus interpreters, and I noticed that most of them just substituted the values of the parameter with the actual value when the function was called. I was able to achieve this by making a substitute function and a syntax parameter "body" that basically does the same thing as env did accept it takes syntax and returns it quoted and the syntax-parameterize part made body substitute the parameter for its value: (define-syntax (new-lambda stx) (syntax-case stx () [(_ (parameter) body) #`(letrec ([L (lambda-structure 'parameter (*body body) (lambda (parameter) (syntax-parameterize ([*body (lambda (stx) (syntax-case stx () [(_ b) #`(substitute 'b 'parameter parameter)]))]) body)))]) L)])) (define-syntax-parameter *body (syntax-rules () [(_ b) 'b])) This works ok, but it doesn't actually evaluate the body, ((lambda (x) (lambda (y) (x y))) (lambda (z) f)) will display (lambda (y) (lambda (z) f) y) instead of (lambda (y) f). I can make this work by evaluating s-expressions since I can just eval the body after the substitution, but is there any way to do this in racket? -- 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.