From: bolega on 10 Jun 2010 01:34 My apologies in advance to comp.lang.scheme and comp.lang.lisp. I am trying to run a certain syntax inside emacs lisp. I know basically how let works (let (list of pairs of var value) (function)) This is like a lambda function call , only the order is different. But the novelty i saw reading a book on common lisp or scheme is this and i failed to run in emacs. plz tell what modifications are needed and i know they are different. ( (lambda (n) (+ 1 n)) 3) ;;; works in emacs (let ((a (lambda (n) (+ 1 n))) (b 3)) (a b)) ;;; does NOT work in emacs basically we are trying to use / abuse the let in that in the pair we define a equal to a lambda. Then another pair where a value of b is defined. next, we want a to operate on b. Why does it fail ? The scheme/lisp book/paper where it was seen (forgot) used letrec. Can someone enlighten me how set! and let can be used to formulate recursion when the let has no recursion built in it ? thanks a lot. cheers
From: bolega on 10 Jun 2010 01:37 let me write it more clearly with indents as follows : (let ((a (lambda (n) (+ 1 n))) (b 3)) (a b)) On Jun 9, 10:34 pm, bolega <gnuist...(a)gmail.com> wrote: > My apologies in advance to comp.lang.scheme and comp.lang.lisp. > > I am trying to run a certain syntax inside emacs lisp. > > I know basically how let works > > (let (list of pairs of var value) (function)) > > This is like a lambda function call , only the order is different. > > But the novelty i saw reading a book on common lisp or scheme is this > and i failed to run in emacs. plz tell what modifications are needed > and i know they are different. > > ( (lambda (n) (+ 1 n)) 3) ;;; works in emacs > > (let > ((a (lambda (n) (+ 1 n))) (b 3)) (a b)) ;;; does NOT work in emacs > > basically we are trying to use / abuse the let in that in the pair we > define a equal to a lambda. Then another pair where a value of b is > defined. > > next, we want a to operate on b. > > Why does it fail ? > > The scheme/lisp book/paper where it was seen (forgot) used letrec. > > Can someone enlighten me how set! and let can be used to formulate > recursion when the let has no recursion built in it ? > > thanks a lot. > cheers
From: bolega on 10 Jun 2010 01:37 let me write it more clearly with indents as follows : (let ((a (lambda (n) (+ 1 n))) (b 3)) (a b)) On Jun 9, 10:34 pm, bolega <gnuist...(a)gmail.com> wrote: > My apologies in advance to comp.lang.scheme and comp.lang.lisp. > > I am trying to run a certain syntax inside emacs lisp. > > I know basically how let works > > (let (list of pairs of var value) (function)) > > This is like a lambda function call , only the order is different. > > But the novelty i saw reading a book on common lisp or scheme is this > and i failed to run in emacs. plz tell what modifications are needed > and i know they are different. > > ( (lambda (n) (+ 1 n)) 3) ;;; works in emacs > > (let > ((a (lambda (n) (+ 1 n))) (b 3)) (a b)) ;;; does NOT work in emacs > > basically we are trying to use / abuse the let in that in the pair we > define a equal to a lambda. Then another pair where a value of b is > defined. > > next, we want a to operate on b. > > Why does it fail ? > > The scheme/lisp book/paper where it was seen (forgot) used letrec. > > Can someone enlighten me how set! and let can be used to formulate > recursion when the let has no recursion built in it ? > > thanks a lot. > cheers
From: bolega on 10 Jun 2010 02:18 On Jun 9, 10:37 pm, bolega <gnuist...(a)gmail.com> wrote: > let me write it more clearly with indents as follows : > > (let > ((a (lambda (n) (+ 1 n))) > (b 3)) > (a b)) > > On Jun 9, 10:34 pm, bolega <gnuist...(a)gmail.com> wrote: > > > My apologies in advance to comp.lang.scheme and comp.lang.lisp. > > > I am trying to run a certain syntax inside emacs lisp. > > > I know basically how let works > > > (let (list of pairs of var value) (function)) > > > This is like a lambda function call , only the order is different. > > > But the novelty i saw reading a book on common lisp or scheme is this > > and i failed to run in emacs. plz tell what modifications are needed > > and i know they are different. > > > ( (lambda (n) (+ 1 n)) 3) ;;; works in emacs > > > (let > > ((a (lambda (n) (+ 1 n))) (b 3)) (a b)) ;;; does NOT work in emacs > > > basically we are trying to use / abuse the let in that in the pair we > > define a equal to a lambda. Then another pair where a value of b is > > defined. > > > next, we want a to operate on b. > > > Why does it fail ? > > > The scheme/lisp book/paper where it was seen (forgot) used letrec. > > > Can someone enlighten me how set! and let can be used to formulate > > recursion when the let has no recursion built in it ? > > > thanks a lot. > > cheers The following works where I have replaced the association of lambda to a _by_ the association of lambda function call to a, ie a numerical value. (let ((a ((lambda (n) (+ 1 n)) 5)) (b 3)) (+ a b)) I am sure I am making some trivial mistake
From: David Kastrup on 10 Jun 2010 03:22
bolega <gnuist006(a)gmail.com> writes: > let me write it more clearly with indents as follows : > > (let > ((a (lambda (n) (+ 1 n))) > (b 3)) > (a b)) Scheme does not have separate value and function cells for symbols. Lisp does. let binds the value cell of a function. To call a function in the value cell of a symbol, use funcall. To bind a lambda formto the function cell of a symbol, use flet (from the cl library). So you can do either (let ((a (lambda (n) (+ 1 n))) (b 3)) (funcall a b)) or (eval-when-compile (require 'cl)) (flet ((a (n) (+ 1 n))) (let ((b 3)) (a b))) -- David Kastrup |