If you declare a variable special, it's accessible from any other function that uses that symbol name for a variable in a context where it's special. I.e., the symbol used to name it is a "global symbol associated with the variable."virex wrote:Also if you really need to, you can use (declare (special variable)) directly after a let-form's variable definition to tell the compiler that variable is special, which allows shadowing, but prevents outside access since there is no global symbol associated with the variable, so you have a special local variable then.
help understanding a simple function
Re: help understanding a simple function
Re: help understanding a simple function
Oh thanks. I should realy have tested thatPaul wrote:If you declare a variable special, it's accessible from any other function that uses that symbol name for a variable in a context where it's special. I.e., the symbol used to name it is a "global symbol associated with the variable."virex wrote:Also if you really need to, you can use (declare (special variable)) directly after a let-form's variable definition to tell the compiler that variable is special, which allows shadowing, but prevents outside access since there is no global symbol associated with the variable, so you have a special local variable then.

Re: help understanding a simple function
...
Actually, to solve the task recursively, I'ld propose a solution quite similar to your attempt above.
You just don't need this new-lst variable.
That is, if you do (cons 1 ()) you get a new list, so there is no need to establish an explicit binding in numbers...
Just cons each number on the value of the recursive application until you reach nil. Then return nil. So the call tree would evaluate to sth. like this:
Code: Select all
(defun numbers (lst)
(setq new-lst '())
(cond
((numberp (car lst)) (cons (car lst) new-lst) (numbers (cdr lst)))
((null lst) new-lst)
(t (numbers (cdr lst)))))
You just don't need this new-lst variable.
That is, if you do (cons 1 ()) you get a new list, so there is no need to establish an explicit binding in numbers...
Just cons each number on the value of the recursive application until you reach nil. Then return nil. So the call tree would evaluate to sth. like this:
Code: Select all
(numbers '(1 2 a b 3 4)) => (cons 1 (cons 2 (cons 3 (cons 4 nil))))
Re: help understanding a simple function
I thought I'd post a quick update.
Once again, thank you everyone for the help so far. I haven't posted anything in a while. I haven't forgotten about this thread:)
The only reason for that is that I've got a very busy period at work and have to bring a lot of paperwork home so don't really
have time for lisp. I think I'll have more time in a week or so and will be able to come back to this thread.
See you soon.
Once again, thank you everyone for the help so far. I haven't posted anything in a while. I haven't forgotten about this thread:)
The only reason for that is that I've got a very busy period at work and have to bring a lot of paperwork home so don't really
have time for lisp. I think I'll have more time in a week or so and will be able to come back to this thread.
See you soon.