Re: [racket-users] making a language that can return the body of a function

2017-05-29 Thread Vityou
It turns out that I can just do:

(define-syntax (new-lambda stx) 
  (syntax-parse stx
[(_ (parameter:id) body:expr) 
 #'(lambda-structure 'parameter
 body
 (lambda (parameter)
   body))]))

because my lambda-calculus language treats undefined variables as a special 
struct that can be applied, so the body won't complain about undefined 
variables.  I also realized that I could change body to some error handling 
expression wrapped around (let ([parameter 'parameter]) body) and if there is 
an error I would just quote body since it isn't a lambda expression.


On Monday, May 29, 2017 at 7:11:31 AM UTC-6, Matthias Felleisen wrote:
> This is totally different technology. See 
> http://www.ccs.neu.edu/racket/pubs/#esop2001-cff
> 
> 
> > On May 28, 2017, at 11:17 PM, Vityou  wrote:
> > 
> > I just noticed that the stepper for intermediate student with lambda pretty 
> > much does what I want.  I guess I can look into that.
> > 
> > On Sunday, May 28, 2017 at 7:55:08 PM UTC-6, Matthias Felleisen wrote:
> >> I misunderstood because of your mismatched parentheses. Without eval, you 
> >> can’t do better than that. Parens rock. 
> >> 
> >> 
> >>> On May 28, 2017, at 9:51 PM, Vityou  wrote:
> >>> 
> >>> On Sunday, May 28, 2017 at 2:01:09 PM UTC-6, Matthias Felleisen wrote:
>  You need to apply the function, not just compute the substitution. See 
>  applicable struct in previous message. This should just work out, w/o 
>  much ado. 
>  
>  
>  
> > On May 28, 2017, at 12:40 AM, Vityou  wrote:
> > 
> > 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  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  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)
> >>> 
> >>> 
> >>> 

Re: [racket-users] making a language that can return the body of a function

2017-05-29 Thread Matthias Felleisen

This is totally different technology. See 
http://www.ccs.neu.edu/racket/pubs/#esop2001-cff


> On May 28, 2017, at 11:17 PM, Vityou  wrote:
> 
> I just noticed that the stepper for intermediate student with lambda pretty 
> much does what I want.  I guess I can look into that.
> 
> On Sunday, May 28, 2017 at 7:55:08 PM UTC-6, Matthias Felleisen wrote:
>> I misunderstood because of your mismatched parentheses. Without eval, you 
>> can’t do better than that. Parens rock. 
>> 
>> 
>>> On May 28, 2017, at 9:51 PM, Vityou  wrote:
>>> 
>>> On Sunday, May 28, 2017 at 2:01:09 PM UTC-6, Matthias Felleisen wrote:
 You need to apply the function, not just compute the substitution. See 
 applicable struct in previous message. This should just work out, w/o much 
 ado. 
 
 
 
> On May 28, 2017, at 12:40 AM, Vityou  wrote:
> 
> 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  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  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  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? 
>>> 
>>> 
>>> 

Re: [racket-users] making a language that can return the body of a function

2017-05-28 Thread Vityou
I just noticed that the stepper for intermediate student with lambda pretty 
much does what I want.  I guess I can look into that.

On Sunday, May 28, 2017 at 7:55:08 PM UTC-6, Matthias Felleisen wrote:
> I misunderstood because of your mismatched parentheses. Without eval, you 
> can’t do better than that. Parens rock. 
> 
> 
> > On May 28, 2017, at 9:51 PM, Vityou  wrote:
> > 
> > On Sunday, May 28, 2017 at 2:01:09 PM UTC-6, Matthias Felleisen wrote:
> >> You need to apply the function, not just compute the substitution. See 
> >> applicable struct in previous message. This should just work out, w/o much 
> >> ado. 
> >> 
> >> 
> >> 
> >>> On May 28, 2017, at 12:40 AM, Vityou  wrote:
> >>> 
> >>> 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  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  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  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  wrote:
> > 
> > I might be able to do 

Re: [racket-users] making a language that can return the body of a function

2017-05-28 Thread Matthias Felleisen

I misunderstood because of your mismatched parentheses. Without eval, you can’t 
do better than that. Parens rock. 


> On May 28, 2017, at 9:51 PM, Vityou  wrote:
> 
> On Sunday, May 28, 2017 at 2:01:09 PM UTC-6, Matthias Felleisen wrote:
>> You need to apply the function, not just compute the substitution. See 
>> applicable struct in previous message. This should just work out, w/o much 
>> ado. 
>> 
>> 
>> 
>>> On May 28, 2017, at 12:40 AM, Vityou  wrote:
>>> 
>>> 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  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  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  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  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 

Re: [racket-users] making a language that can return the body of a function

2017-05-28 Thread Vityou
On Sunday, May 28, 2017 at 2:01:09 PM UTC-6, Matthias Felleisen wrote:
> You need to apply the function, not just compute the substitution. See 
> applicable struct in previous message. This should just work out, w/o much 
> ado. 
> 
> 
> 
> > On May 28, 2017, at 12:40 AM, Vityou  wrote:
> > 
> > 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  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  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  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  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 

Re: [racket-users] making a language that can return the body of a function

2017-05-28 Thread Matthias Felleisen

You need to apply the function, not just compute the substitution. See 
applicable struct in previous message. This should just work out, w/o much ado. 



> On May 28, 2017, at 12:40 AM, Vityou  wrote:
> 
> 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  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  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  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  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 

Re: [racket-users] making a language that can return the body of a function

2017-05-27 Thread Vityou
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  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  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  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  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)
> 

Re: [racket-users] making a language that can return the body of a function

2017-05-25 Thread Matthias Felleisen

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  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  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  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  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))])

Re: [racket-users] making a language that can return the body of a function

2017-05-25 Thread Vityou
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  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  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  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 

Re: [racket-users] making a language that can return the body of a function

2017-05-24 Thread Matthias Felleisen

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  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  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  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 `((λ 

Re: [racket-users] making a language that can return the body of a function

2017-05-24 Thread Vityou
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  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  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.


Re: [racket-users] making a language that can return the body of a function

2017-05-24 Thread Vityou
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  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  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)))

-- 
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.


Re: [racket-users] making a language that can return the body of a function

2017-05-23 Thread Matthias Felleisen
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  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  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+unsubscr...@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.

-- 
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.


Re: [racket-users] making a language that can return the body of a function

2017-05-23 Thread Vityou
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  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+unsubscr...@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.

-- 
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.


Re: [racket-users] making a language that can return the body of a function

2017-05-23 Thread Vityou
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] making a language that can return the body of a function

2017-05-23 Thread Philip McGrath
I think you will probably want to define an applicable struct type with
custom printing behavior and then replace Racket's lambda with your own
macro to create instances of that struct type. I think what you want may be
more complex than this, but here's an example that simply carries along its
own source text:

#lang racket

(require (for-syntax syntax/parse))

(struct my-lambda-record (name proc)
  #:property prop:custom-print-quotable 'never
  #:methods gen:custom-write
  [(define (write-proc this out mode)
 (print (my-lambda-record-name this) out 1))]
  #:property prop:procedure (struct-field-index proc))

(define-syntax (my-lambda stx)
  (syntax-parse stx
[(_ (formal:id) body:expr)
 #`(my-lambda-record '#,stx (lambda (formal) body))]))


Then for example:


> (my-lambda (x) (my-lambda (y) x))
(my-lambda (x) (my-lambda (y) x))



-Philip

On Tue, May 23, 2017 at 4:10 PM, Vityou  wrote:

> In lambda calculus, the function is the only datatype, so it would be
> useful to see the body of a function when it is returned in some expression
> in the repl (so you can see what number was returned or some other
> encoding).  I have got this working by making a language where the reader
> turns the file into a list and #%module-begin just prints the result of
> applying an eval function that works with lists to the list from the
> reader.  This works quite well:
>
> > x
> x
> > ((lambda (x) (lambda (y) x)) f)
> (function (lambda (y) x) ((x f)))
>
>
> but I was thinking of including some things like a non-recursive define
> and provide and require, but the current list based system I have right now
> won't work.  Is there any way that I could have racket print its own
> lambdas like mine above?  Or is there any way to achieve the same effect
> (the effect being able to print lambdas like above and use define require
> and provide).  I attached the expander of the list based lambda calculus if
> you want to look at it.
>
> --
> 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.
>

-- 
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.


[racket-users] making a language that can return the body of a function

2017-05-23 Thread Vityou
In lambda calculus, the function is the only datatype, so it would be useful to 
see the body of a function when it is returned in some expression in the repl 
(so you can see what number was returned or some other encoding).  I have got 
this working by making a language where the reader turns the file into a list 
and #%module-begin just prints the result of applying an eval function that 
works with lists to the list from the reader.  This works quite well:

> x
x
> ((lambda (x) (lambda (y) x)) f)
(function (lambda (y) x) ((x f)))


but I was thinking of including some things like a non-recursive define and 
provide and require, but the current list based system I have right now won't 
work.  Is there any way that I could have racket print its own lambdas like 
mine above?  Or is there any way to achieve the same effect (the effect being 
able to print lambdas like above and use define require and provide).  I 
attached the expander of the list based lambda calculus if you want to look at 
it.

-- 
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.


expander.rkt
Description: Binary data