make a function like lambda

Q&A's, tips, howto's

make a function like lambda

Postby ssqq » Mon Jun 16, 2014 5:50 pm

I want design a function:

Code: Select all
(context 'extend-env)
(extend-env:filter 1 2 3) --> (extend-env:filter 1 2 3)


In this context, some primitive function call would not evalute anything.

How to design this function?
ssqq
 
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: make a function like lambda

Postby ralph.ronnquist » Tue Jun 17, 2014 1:21 am

What about:
Code: Select all
(define (extend-env:filter) (cons 'extend-env:filter (args))

or, if you don't want its arguments to be evaluated:
Code: Select all
(define-macro (extend-env:filter) (cons 'extend-env:filter (args))
ralph.ronnquist
 
Posts: 213
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: make a function like lambda

Postby ssqq » Tue Jun 17, 2014 2:55 am

Thanks ralph.ronnquist!

I want make a extend enviroment (context) to prevent all primitive function to evualte.

Code: Select all
(new Class 'extend-env)

(define (create-funcs f)
  (set (eval f) (append (lambda ()) (list (list 'cons f '(args))))))

(setq built-in (difference
                 (filter eval (symbols))
                 '(define context MAIN Class Tree create-funcs)))

(map create-funcs (map quote (map (fn (x) (sym x 'extend-env)) built-in)))

(save "extend-env.lsp" 'extend-env)
ssqq
 
Posts: 88
Joined: Sun May 04, 2014 12:49 pm


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests