Re: help executing a list
From: David Wallis (dww_at_cpom.ucl.ac.uk)
Date: 10/19/04
- Next message: nikodemus_at_random-state.net: "Re: eval-when -- pls check my understanding"
- Previous message: Adam Warner: "Re: enclose, was Re: Sacla loop: a new loop implementation"
- In reply to: Matthew Danish: "Re: help executing a list"
- Next in thread: Matthew Danish: "Re: help executing a list"
- Reply: Matthew Danish: "Re: help executing a list"
- Reply: Mario S. Mommer: "Re: help executing a list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 19 Oct 2004 11:22:14 +0100
>
(Sorry for long post)
Thanks for the response, but I'm afraid I didn't really understand what
you mean. (This is my first lisp program)
Maybe you could expand a bit?
Also, despite reading all the apropriate bits in Paul Graham's 'Common
Lisp', I'm still stuck.The approach I was taking [based on Svein Ove Aas'
reply] was to pass a function to my argument f and call it in
(dotimes (i (array-total-size a))
(setf (row-major-aref r i) f))
I have 2 questions.
1. I have a function that can return a list like (+ (row-major-aref (svref
v 0) i) 2 pi) , or just the argument. However the
function contains a loop. I can't figure out how to build the function
(closure?) in a loop, iterating over my arguments. Or, if I just return a
list, ((row-major-aref (svref v 0) i) 2 pi) ) and call (apply #'+ ...), it
tells me that (row-major-aref (svref v 0) i) isn't a number (it hasn't
evaluated the expression, it's just passed it to +). How do I build a
function iteratively? My
code to build the arguments is
(defun make-args (lst)
(let ((v (list-to-vec lst)) ; list-to-vec could be (coerce lst
'array)
(r Nil))
(dotimes (i (length lst))
(if (arrayp (svref v i))
(setf r (append1 r `(row-major-aref (svref v ,i)
i))) ; append1 is just (append lst (list obj))
(setf r (append1 r (svref v i))))) r ))
>(make-args '(#(1 2 3) 2))
((ROW-MAJOR-AREF (SVREF V 0) I) 2)
What I want is the function:
(lambda (v i) (+ ((ROW-MAJOR-AREF (SVREF V 0) I) 2))
2. Will this approach invoke the compiler in the loop? The arguments to my
array operator do not change in the loop.
e.g. if I call (.+ #(1 2 3) 2) [where .+ is my array addition operator),
my function would be
(+ (row-major-aref (svref v 0)) 2). So I hoped I could build the function
before going into the loop that iterates over the array #(1 2 3) and it
should be fast?
> The proper solution is to pass around a function and call it with
> the values to be bound.
>
> (defun f (...)
> ...)
>
> (defun g (fn ...)
> ...
> (funcall fn ...)
> ...)
>
> (g #'f ...) or (g #'(lambda (...) ...) ...) for anonymous function.
>
- Next message: nikodemus_at_random-state.net: "Re: eval-when -- pls check my understanding"
- Previous message: Adam Warner: "Re: enclose, was Re: Sacla loop: a new loop implementation"
- In reply to: Matthew Danish: "Re: help executing a list"
- Next in thread: Matthew Danish: "Re: help executing a list"
- Reply: Matthew Danish: "Re: help executing a list"
- Reply: Mario S. Mommer: "Re: help executing a list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|