[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extending apply

From: Ian Grant
Subject: Re: Extending apply
Date: Mon, 22 Jan 2007 17:07:28 +0000

On Mon, 22 Jan 2007 10:46:15 +0100
Andy Wingo <address@hidden> wrote:

> Have you tried generics? A couple minutes of tinkering didn't give me
> the right incantation, but it should be something like:
> (use-modules (oop goops))
> (define apply (ensure-generic apply))
> (define-method (apply proc (x <vector>)) ...)

Hi Andy

Many thanks for that! It hadn't occurred to me. The stuff below does
what I want with apply. Now I need to figure out how to get this version
of apply into the top-level REPL. At the moment:

guile> (define tvec (vector cos sin))
guile> (apply tvec '(3.1415))
#(-0.999999995707656 9.26535896609343e-5)
guile> (tvec 3.1415)
<unnamed port>:12:1: In expression (tvec 3.1415):
<unnamed port>:12:1: Wrong type to apply: #(#<procedure cos (z)>
#<procedure sin (z)>)
ABORT: (misc-error)

Type "(backtrace)" to get more information or "(debug)" to enter the

I have tried starting a new (top-repl) after defining apply but that
doesn't work. Any ideas anyone?


;; Here's the code

(use-modules (oop goops))

(define apply (ensure-generic apply))

(define (vapp vec args)
    (list->vector (map (lambda (p) (apply p args)) (vector->list vec))))

(define-method (apply (vec <vector>) args) (vapp vec args))

;; To test:
(define tvec (vector cos sin))
(apply tvec '(3.1415))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]