guile-user
[Top][All Lists]
Advanced

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

Re: scheme (format) question


From: Kjetil S. Matheussen
Subject: Re: scheme (format) question
Date: Mon, 23 Mar 2009 13:27:14 +0100 (CET)



On Sun, 22 Mar 2009, Mark Polesky wrote:


(define (my-format bool string . list-of-nums)
 (apply format bool string (map set-precision list-of-nums)))

(let ((a 2.0)
      (b 1/4)
      (c 1/3))
 (my-format #t "~&~a ~a ~a" a b c))


Kjetil,

Awesome. Thanks. I knew there was something simple,
I just couldn't figure it out. That little dot helps
alot! And now for my next question...

Is there a way for a pair within an alist to retrieve
values from other pairs within the same alist? I know
the following code doesn't work, because "my-alist"
is still undefined when I'm calling it, but is there
a way to make it do what I want?

(define my-alist
 `((a 1)
   (b ,(+ 1 (cadr (assq 'a my-alist))))))


Maybe something like this:

(define-macro (push! val where)
  (let ((ret (gensym)))
    `(let ((,ret ,val))
       (set! ,where (cons ,ret ,where))
       ,ret)))

(define my-alist '())

(push! '(a 1) my-alist)
(push! `(b ,(+ 1 (cadr (assq 'a my-alist)))) my-alist)






reply via email to

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