[CM] something like let-set! for undefined vars?

Christos Vagias chris.actondev at gmail.com
Sun Feb 7 01:23:44 PST 2021

Hi Iain!
Indeed lets are amazingly powerful :)

I think what you're looking for here is (apply varlet env args)

On Sun, Feb 7, 2021, 05:58 Iain Duncan <iainduncanlists at gmail.com> wrote:

> Answering myself! Just didn't understand the docs properly, got it all
> working nicely with varlet.
> Though I am curious to know whether my way of iterating through a keyword
> assoc list in a constructor is reasonable. This is what I'm doing, feedback
> most welcome:
>     ;  loop through the init-args keyword arg list, which is an assoc list
> of sym/value to set
>     ; this allows setting any instance vars from keyword list to
> constructor
>     (let* init-loop ((args init-args))
>       (if (not (null? args))
>         (begin
>           (varlet env (car args) (cadr args))
>           (init-loop (cddr args)))))
> On Sat, Feb 6, 2021 at 5:06 PM Iain Duncan <iainduncanlists at gmail.com>
> wrote:
>> Hi folks, I've been digging into S7s environment support and loving it. I
>> have implemented a really convenient pseudo-inheritance-through-delegation
>> setup for my process objects, and one thing I'm using is the let-set!
>> function to allow updating internal variables from outside if desired. My
>> little method looks like this (in side of a let inside a function)
>> (define (set sym val)
>>       ;; TODO this doesn't allow setting values that are not yet set
>>       ;; need to check if symbol is in let and then set it
>>       (let-set! proc-env sym val))
>> However, this of course errors if I try to use if and sym is not defined.
>> I tried mucking about with the defined?  predicate, but got confused by the
>> docs. If anyone can tell me how I can easily add to the above the
>> following, that would be lovely:
>> - if sym not defined in proc-env, define sym to val
>> iain
>> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> https://cm-mail.stanford.edu/mailman/listinfo/cmdist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20210207/8aa536e3/attachment-0001.html>

More information about the Cmdist mailing list