is there a function like values that would allow me to do this?
Code: Select all
(* (values 3 4)) ;; doesn't work, but is there something that does?
Code: Select all
(* (values 3 4)) ;; doesn't work, but is there something that does?
Code: Select all
(multiple-value-call #'* (values 3 4)) => 12
Code: Select all
(apply #'* (list 3 4)) => 12
YES! Both methods are more than sufficient. One further question in regards to values, the objects returned by the function aren't really a list:edgar-rft wrote:Sorry, but it's not really clear what you mean. If you want to use #'* with multiple values then use MULTIPLE-VALUE-CALL:
If you want to replace VALUES by a different function then you could use APPLY and LIST:Code: Select all
(multiple-value-call #'* (values 3 4)) => 12
Is this what you're looking for?Code: Select all
(apply #'* (list 3 4)) => 12
Code: Select all
(funcall (funcall (lambda(f)(lambda(a)(apply f a)))#'*) (values 3 7)) ;; I initially used FUNCALL in the lambda body
;; returns : APPLY: argument list given to * is dotted (terminated by 3) ???!!
(funcall (funcall (lambda(f)(lambda(a)(apply f a)))#'*) '(3 7))
;; returns : 21
Code: Select all
(funcall (funcall (lambda (f) (lambda (a) (apply f a))) #'*) (values 3 7))
=> APPLY: argument list given to * is dotted (terminated by 3)
Code: Select all
(funcall (lambda (a) ...) (values 3 7))
Thanks, I've read the section in PCL, it was really good, and will read the others you listed in a bit.edgar-rft wrote: The reason is that Common Lisp functions do not handle multiple values by default.
Multiple values are explained here:
CLtL2 is older than the ANSI Common Lisp specification, so in case of doubt look-up the MULTIPLE-VALUE-... operators in CLHS, but the explanation in CLtL2 is much better than CLHS Section 5.1.2.3 VALUES Forms as Places.
- Practical Common Lisp, Chapter 20, Section Multiple Values
- Common Lisp, the Language, 2nd Edition [CLtL2], Section 7.10.1 Constructs for Handling Multiple Values
Frankly, I have to agree with your opinion. I've run into many situations where the errors returned have given little or incomplete information. I'm also frustrated by its lack of built-in thread support. If you know of a good implementation that plays well with Emacs/Slime and does threads right out the box, let me know. Again, thanks for your help.edgar-rft wrote: The error message is misleading. IMO this is is a bug in your Common Lisp implementation. A correct error message should read "The value 3 is not of type LIST" or similar.
It will be a few months before I have FreeBSD up and running again, so I almost gave up until I found this, which is a fork of a fork of SBCL by Anton Kovalenko. I installed, ran it, and of course tested it:SBCL wrote: Threads are part of the default build on x86[-64] Linux only.
They are also experimentally supported on: x86[-64] Darwin (Mac OS X), x86[-64] FreeBSD, x86 SunOS (Solaris), and PPC Linux. On these platforms threads must be explicitly enabled at build-time, see INSTALL for directions.
Code: Select all
(make-thread (lambda()(write-line "Hello, world")))
;;; caught STYLE-WARNING:
; undefined function: MAKE-THREAD
;
; compilation unit finished
; Undefined function:
; MAKE-THREAD
Code: Select all
* (sb-thread::make-thread (lambda()(write-line "Hello")))
Hello
#<SB-THREAD:THREAD RUNNING {23E1BB49}>
See the SBCL User Manual, Section 12 Threading.macrolyte wrote:... how the heck do I kill the thread?