guile-user
[Top][All Lists]
Advanced

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

Re: sph.io libraries


From: tantalum
Subject: Re: sph.io libraries
Date: Tue, 22 Jul 2014 13:12:28 +0200
User-agent: Posteo Webmail

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?
the new process receives only the specified environment variables. but it should be no problem to pass it a modified environment from the current process using guiles "environ" procedure
  (cons "XX2=LOL" (environ))
working example:
guile -c '(import (sph process)) (execute-with-environment (cons "XX2=LOL" (environ)) "env")'

the only interface to execve for guile
actually in guile the direct interface to execve is called execle (https://www.gnu.org/software/guile/manual/html_node/Processes.html#index-execle).
the "process" version does two more things:
- it adds the program name as the first argument, the usual calling convention. would have to be taken care of manually otherwise
- it may search $PATH
- it moves the "env" argument to the front to preserve the order of filename and rest-arguments

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 :)

the getter/setter definitions where included in the last example. setting fields by symbolic name would look like this:
  (define triad (make-record-layout (quote (pid env num))))
  (define t (record triad pid "LOL" 5))
  (record-set! t triad (quote pid) 5011)

the getter/setter definitions could be shortened with a new single "define-" form which generates the bindings. i might add that and the current library makes this quite easy. for reference, other record implementations already do this, but these implementations regard records as something more complicated.
https://www.gnu.org/software/guile/manual/html_node/rnrs-records-syntactic.html#rnrs-records-syntactic
https://www.gnu.org/software/guile/manual/html_node/SRFI_002d9-Records.html#SRFI_002d9-Records

if you do not want to deal with record-layouts, getters and setters,
you could use vectors which are like arrays in other languages (which could be records at the same time)
  (define a (vector 3 4 5))
  (vector-ref a 0)

or hashtables, which are like associative arrays or objects in other languages
  (import (sph hashtable))
  (define a (hashtable "a" 1 "b" 2))
  (hashtable-ref a "a")

or association lists, alists, which are lists and similar to two-dimensional arrays
  (import (sph alist))
  (define a (alist "a" 1 "b" 2))
  (alist-ref a "a")

(https://www.gnu.org/software/guile/manual/html_node/Association-Lists.html#Association-Lists
https://www.gnu.org/software/guile/manual/html_node/SRFI_002d1-Association-Lists.html#SRFI_002d1-Association-Lists)

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

your libraries to be packaged and readily available in my distro repositories
what is your distro?
there is a package for arch linux at least (https://aur.archlinux.org/packages/sph-lib-git) and there is "guix", which seems to become the package manager for the gnu system, and might be interesting cross-distro. though as of yet i have not figured out how to make a package for it.




reply via email to

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