- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]

From: Harvey J. Stein <hjstein_at_MATH.HUJI.AC.IL>

Date: Thu, 13 Apr 1995 16:54:33 +0300

I'm having a little trouble doing indirection through symbols and am

hoping someone on the list can help me.

The setting is I wrote a table-widget for STk. It basically consists

of a matrix of entry widgets, each of which is tied to an STk

variable. The table-widget manages a matrix of data. Scrolling is

accomplished by resetting all the variables to a different submatrix

of the data.

I was originally doing something like:

(for-each (lambda (x y) (eval `(set! ,x ,y)))

variable-list

value-list)

where variable-list was something like (|G11| |G12| ...) and

value-list is just the list of values to use.

The problem is that this is slow, and I traced it down to the (eval

`set! ,x ,y) being slow. I discovered that defining a macro for this

speeded things up by a factor of 10! But, the macro didn't work

inside of a function!

Here's a simple example of the problem I was having:

STk> (define foo 'a)

#[undefined]

STk> (define a 3)

#[undefined]

STk> a

3

STk> (eval `(set! ,foo 6))

#[undefined]

STk> foo

a

STk> a

6

Thus, if foo's value is a symbol, I can set the value of this symbol

(to 6 for example) with the expression:

(eval `(set! ,foo 6))

However, this is slow. On the other hand, the following is much

faster (by about a factor of 10!):

(define-macro (superset! a b) `(set! ,(eval a) ,b))

The above macro also works:

STk> foo

a

STk> a

6

STk> (define-macro (superset! a b) `(set! ,(eval a) ,b))

#[undefined]

STk> (superset! foo 19)

#[undefined]

STk> foo

a

STk> a

19

My problem is that the above doesn't work inside a function:

(define (bad-guy x y) (superset! x y))

STk> (define (bad-guy x y) (superset! x y))

#[undefined]

STk> foo

a

STk> a

19

STk> (bad-guy foo 3)

*** Error:

unbound variable: x

Current eval stack:

__________________

0 x

1 (eval a)

2 (quasiquote (set! (unquote (eval a)) (unquote b)))

3 (%replace params (apply (lambda (a b) (quasiquote (set! (unquote (eval a)) (unquote b)))) (cdr params)))

4 (superset! x y)

Anyone have any idea of how to do this?

Thanks,

Received on Thu Apr 13 1995 - 15:55:38 CEST

Date: Thu, 13 Apr 1995 16:54:33 +0300

I'm having a little trouble doing indirection through symbols and am

hoping someone on the list can help me.

The setting is I wrote a table-widget for STk. It basically consists

of a matrix of entry widgets, each of which is tied to an STk

variable. The table-widget manages a matrix of data. Scrolling is

accomplished by resetting all the variables to a different submatrix

of the data.

I was originally doing something like:

(for-each (lambda (x y) (eval `(set! ,x ,y)))

variable-list

value-list)

where variable-list was something like (|G11| |G12| ...) and

value-list is just the list of values to use.

The problem is that this is slow, and I traced it down to the (eval

`set! ,x ,y) being slow. I discovered that defining a macro for this

speeded things up by a factor of 10! But, the macro didn't work

inside of a function!

Here's a simple example of the problem I was having:

STk> (define foo 'a)

#[undefined]

STk> (define a 3)

#[undefined]

STk> a

3

STk> (eval `(set! ,foo 6))

#[undefined]

STk> foo

a

STk> a

6

Thus, if foo's value is a symbol, I can set the value of this symbol

(to 6 for example) with the expression:

(eval `(set! ,foo 6))

However, this is slow. On the other hand, the following is much

faster (by about a factor of 10!):

(define-macro (superset! a b) `(set! ,(eval a) ,b))

The above macro also works:

STk> foo

a

STk> a

6

STk> (define-macro (superset! a b) `(set! ,(eval a) ,b))

#[undefined]

STk> (superset! foo 19)

#[undefined]

STk> foo

a

STk> a

19

My problem is that the above doesn't work inside a function:

(define (bad-guy x y) (superset! x y))

STk> (define (bad-guy x y) (superset! x y))

#[undefined]

STk> foo

a

STk> a

19

STk> (bad-guy foo 3)

*** Error:

unbound variable: x

Current eval stack:

__________________

0 x

1 (eval a)

2 (quasiquote (set! (unquote (eval a)) (unquote b)))

3 (%replace params (apply (lambda (a b) (quasiquote (set! (unquote (eval a)) (unquote b)))) (cdr params)))

4 (superset! x y)

Anyone have any idea of how to do this?

Thanks,

Received on Thu Apr 13 1995 - 15:55:38 CEST

*
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST
*