guile-user
[Top][All Lists]
Advanced

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

Re: [ANN] a lot


From: Max
Subject: Re: [ANN] a lot
Date: Tue, 22 Jul 2014 00:15:04 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

21.07.2014 19:14, tantalum пишет:
>> Are there some code examples?
> except for process-chain-* probably not, but i put that on my todo list.
>
> something like this should work:
>   (execute-with-environment "XX2=LOL" "/tmp/mybin")
>
> working example:
>   guile -c '(import (sph process)) (execute-with-environment (list
> "XX2=LOL") "/usr/bin/echo" "test")'
>
> but this is using the system call "execve", which leads to the whole
> guile process being replaced by the specified program. (execve syscall
> reference: http://man7.org/linux/man-pages/man2/execve.2.html)

Neat. Just to double-check - the environment variables of my current process are
preserved or /tmp/mybin would run with environment consisting only of variables 
which
I've explicitly put into execute-with-environment?

>
> "process-create" creates a new parallel process
> ---
> (define pid
>   (process-create
>     (lambda ()
>       ;this will be executed in a completely cloned new process in the
> background
>       (execute-with-environment "XX2=LOL" "/tmp/mybin"))))
>
> ;now, still in the guile process, send a signal to the new process
> (kill pid SIGINT)
> ---
> now what happens is that a new process is created by cloning, and is
> then immediately replaced by your program. as far as i know this is the
> only way on linux or similar systems to archieve this.

Yes, that's totally fine.

>
> for storing values in a record it would probably be best to use a record
> setter procedure. the library supports setting fields by symbolic name,
> but that is slower.

Could you illustrate that with some code too? I do not plan to have that many 
records
so I'm not concerned with the speed that much :)

> in general, as a sidenote, a record like this differs from an
> association list for example, in that the keys are not stored inside the
> data-structure, but separately: the "layout" stores the field names and
> the positions of where the field values are stored in the records.
> example:
> ---
> (define myrec (make-record-layout (quote (pid env))))
> (define-record-accessors myrec (myrec-pid (quote pid)) (myrec-env (quote
> env)))
> (define-record-setters myrec (myrec-pid-set! (quote pid))
> (myrec-env-set! (quote env)))

Hmm... looks like a boilerplate - I thought those are generated automatically.

> ;two different ways to create a record
> (define a (record myrec pid "LOL"))
> (define b (make-record myrec))
>
> (myrec-pid a)
> (myrec-pid-set! a 3)
> (myrec-env-set! b 2)
> ---

I can also have arbitrary number of fields in the record?

(define triad (make-record-layout (quote (pid env num))))

(define t (record triad pid "LOL" 5))


thanks,
Max.




reply via email to

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