unofficial mirror of gwl-devel@gnu.org
 help / color / mirror / Atom feed
* Guile code snippet
@ 2022-04-20  3:37 Olivier Dion via
  2022-04-20  9:47 ` Ricardo Wurmus
  0 siblings, 1 reply; 11+ messages in thread
From: Olivier Dion via @ 2022-04-20  3:37 UTC (permalink / raw)
  To: gwl-devel

Hi,

Is there an easy way to do code snippet in Guile?  I currently do:
# { guile snippet.scm }


but it would be nice to have embedded snippets, kind of like G-exp I guess:
# scm { the-snippet }

Regards,
old

-- 
Olivier Dion
oldiob.dev



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-20  3:37 Guile code snippet Olivier Dion via
@ 2022-04-20  9:47 ` Ricardo Wurmus
  2022-04-20 16:13   ` Olivier Dion via
  0 siblings, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2022-04-20  9:47 UTC (permalink / raw)
  To: Olivier Dion; +Cc: gwl-devel


Hi Olivier,

> Is there an easy way to do code snippet in Guile?  I currently do:
> # { guile snippet.scm }

The manual introduces how to use code snippets:
https://guixwl.org/manual/html_node/Code-Snippets.html

This

  # { … }

is just a shorthand for

  # /bin/bash -c { … }

You can use any interpreter after the hash, e.g.

  # /bin/guile … { … }

But you could just as well provide a quoted Scheme expression or an
actual G-expression right there, e.g.

   (procedure
    `(call-with-output-file ,(first outputs)
       (lambda (port)
         (format port "Hello, world!~%"))))

-- 
Ricardo


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-20  9:47 ` Ricardo Wurmus
@ 2022-04-20 16:13   ` Olivier Dion via
  2022-04-20 16:26     ` Ricardo Wurmus
  2022-04-20 21:21     ` Ricardo Wurmus
  0 siblings, 2 replies; 11+ messages in thread
From: Olivier Dion via @ 2022-04-20 16:13 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: gwl-devel

On Wed, 20 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
> Hi Olivier,
>
>> Is there an easy way to do code snippet in Guile?  I currently do:
>> # { guile snippet.scm }
>
> The manual introduces how to use code snippets:
> https://guixwl.org/manual/html_node/Code-Snippets.html
>
> This
>
>   # { … }
>
> is just a shorthand for
>
>   # /bin/bash -c { … }
>
> You can use any interpreter after the hash, e.g.
>
>   # /bin/guile … { … }
>
> But you could just as well provide a quoted Scheme expression or an
> actual G-expression right there, e.g.
>
>    (procedure
>     `(call-with-output-file ,(first outputs)
>        (lambda (port)
>          (format port "Hello, world!~%"))))

This does not work in my case for example:

process guile-foo
  packages "guile" "guile-foo"
  procedure
    ` use-modules (foo)

| no code for module (libpatch patch)

and when I try the guile shebang:
# /bin/guile { (display "foo") }

| ERROR: In procedure %resolve-variable:
| Unbound variable: ungexp

-- 
Olivier Dion
oldiob.dev


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-20 16:13   ` Olivier Dion via
@ 2022-04-20 16:26     ` Ricardo Wurmus
  2022-04-20 16:35       ` Olivier Dion via
  2022-04-20 21:21     ` Ricardo Wurmus
  1 sibling, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2022-04-20 16:26 UTC (permalink / raw)
  To: Olivier Dion; +Cc: gwl-devel


Hi Olivier,

> This does not work in my case for example:
>
> process guile-foo
>   packages "guile" "guile-foo"
>   procedure
>     ` use-modules (foo)
>
> | no code for module (libpatch patch)
>
> and when I try the guile shebang:
> # /bin/guile { (display "foo") }
>
> | ERROR: In procedure %resolve-variable:
> | Unbound variable: ungexp

Something’s not right here.  I can reproduce the error; I’ll investigate
and report back.

-- 
Ricardo


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-20 16:26     ` Ricardo Wurmus
@ 2022-04-20 16:35       ` Olivier Dion via
  0 siblings, 0 replies; 11+ messages in thread
From: Olivier Dion via @ 2022-04-20 16:35 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: gwl-devel

On Wed, 20 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
> Hi Olivier,
>
>> This does not work in my case for example:
>>
>> process guile-foo
>>   packages "guile" "guile-foo"
>>   procedure
>>     ` use-modules (foo)
>>
>> | no code for module (libpatch patch)

Oops.  s/libpatch patch/foo/g.

>>
>> and when I try the guile shebang:
>> # /bin/guile { (display "foo") }
>>
>> | ERROR: In procedure %resolve-variable:
>> | Unbound variable: ungexp
>
> Something’s not right here.  I can reproduce the error; I’ll investigate
> and report back.

Okay.  No rush, I'm using # { guile proc.scm } for now.

Awesome work by the way!  This tool is exactly what I needed for my
research!

-- 
Olivier Dion
oldiob.dev


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-20 16:13   ` Olivier Dion via
  2022-04-20 16:26     ` Ricardo Wurmus
@ 2022-04-20 21:21     ` Ricardo Wurmus
  2022-04-21 16:30       ` Olivier Dion via
  1 sibling, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2022-04-20 21:21 UTC (permalink / raw)
  To: Olivier Dion; +Cc: gwl-devel


Hi Olivier,

> and when I try the guile shebang:
> # /bin/guile { (display "foo") }
>
> | ERROR: In procedure %resolve-variable:
> | Unbound variable: ungexp

This is now fixed with commit dceec9ecb9e24252ab9130f7a3626c00b2ff1a68.
I added a new test that checks the generated code when using a custom
interpreter.  Previously, it only checked that the interpreter was
extracted correctly and code was generated at all…

The problem was that we accidentally wrote code to a file that was
supposed to be evaluated so that its *result* could be written to a
file.  It wrote:

(apply system*
  (append (list (string-append (getenv "_GWL_PROFILE")
                (ungexp (sanitize-path (symbol->string name)))))
          …))

…instead of:

(apply system*
  (append (list (string-append (getenv "_GWL_PROFILE")
                "/bin/guile") "-c")
          …))

The cause was the use of a macro.  It is now implemented as a procedure.

It works with the custom interpreter, but also direct Scheme embedding
works fine:

--8<---------------cut here---------------start------------->8---
process run
  packages "guile"
  procedure `(display ,name)

workflow do-the-thing
  processes run
--8<---------------cut here---------------end--------------->8---

Could you please try again and report back?  Thanks in advance!

-- 
Ricardo


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-20 21:21     ` Ricardo Wurmus
@ 2022-04-21 16:30       ` Olivier Dion via
  2022-04-21 18:14         ` Ricardo Wurmus
  0 siblings, 1 reply; 11+ messages in thread
From: Olivier Dion via @ 2022-04-21 16:30 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: gwl-devel

On Wed, 20 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
> Hi Olivier,
>
>> and when I try the guile shebang:
>> # /bin/guile { (display "foo") }
>>
>> | ERROR: In procedure %resolve-variable:
>> | Unbound variable: ungexp
>
> This is now fixed with commit
> dceec9ecb9e24252ab9130f7a3626c00b2ff1a68.

Correct me if I'm wrong, but latest upstream commit is still
bf1e701c610951bec93b2e49d186264100486847.  Did you forgot to git-push?

-- 
Olivier Dion
oldiob.dev


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-21 16:30       ` Olivier Dion via
@ 2022-04-21 18:14         ` Ricardo Wurmus
  2022-04-21 20:08           ` Olivier Dion via
  0 siblings, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2022-04-21 18:14 UTC (permalink / raw)
  To: Olivier Dion; +Cc: gwl-devel


Olivier Dion <olivier.dion@polymtl.ca> writes:

> On Wed, 20 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
>> Hi Olivier,
>>
>>> and when I try the guile shebang:
>>> # /bin/guile { (display "foo") }
>>>
>>> | ERROR: In procedure %resolve-variable:
>>> | Unbound variable: ungexp
>>
>> This is now fixed with commit
>> dceec9ecb9e24252ab9130f7a3626c00b2ff1a68.
>
> Correct me if I'm wrong, but latest upstream commit is still
> bf1e701c610951bec93b2e49d186264100486847.  Did you forgot to git-push?

Indeed!  Sorry about that.

-- 
Ricardo


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-21 18:14         ` Ricardo Wurmus
@ 2022-04-21 20:08           ` Olivier Dion via
  2022-04-21 20:46             ` Ricardo Wurmus
  0 siblings, 1 reply; 11+ messages in thread
From: Olivier Dion via @ 2022-04-21 20:08 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: gwl-devel

On Thu, 21 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
>>> This is now fixed with commit
>>> dceec9ecb9e24252ab9130f7a3626c00b2ff1a68.

I tried this:
--8<---------------cut here---------------start------------->8---
process foo
  packages "guile" "guile-fibers"
  # /bin/guile {
    (use-modules (fibers))
  }

workflow bar
  processes foo
--8<---------------cut here---------------end--------------->8---

and got:
#v+
info: .07 Loading workflow file `test.w'...
info: .75 Computing workflow `bar'...
run: 1.35 Executing: /bin/sh -c /gnu/store/4a49gb4b2ha7hms9jddkzf0d4hj5wqj5-gwl-foo.scm '((inputs) (outputs) (values) (name . "foo"))'
;;; Stat of /home/old/softwares/gwl/ (use-modules (fibers))  failed:
;;; In procedure stat: No such file or directory: "/home/old/softwares/gwl/ (use-modules (fibers)) "
Backtrace:
           0 (primitive-load "/home/old/softwares/gwl/ (use-modules ?")

ERROR: In procedure primitive-load:
In procedure open-file: No such file or directory:
"/home/old/softwares/gwl/ (use-modules (fibers)) "
#v-

seems like the interpreter is trying to stat the concatenation of
/bin/guile and the code.

Also tried this:
--8<---------------cut here---------------start------------->8---
process foo
  packages "guile" "guile-fibers"
  procedure
    . `(begin
        (use-modules (fibers)))


workflow bar
  processes foo
--8<---------------cut here---------------end--------------->8---

and got:
#v+
info: .08 Loading workflow file `test.w'...
info: .75 Computing workflow `bar'...
run: 1.35 Executing: /bin/sh -c /gnu/store/fp7fi4ksr16mlgwncdl38w9nw5a9kn15-gwl-foo.scm '((inputs) (outputs) (values) (name . "foo"))'
Backtrace:
           5 (primitive-load "/gnu/store/fp7fi4ksr16mlgwncdl38w9nw5a?")
In ice-9/eval.scm:
    619:8  4 (_ #(#(#(#(#(#(#(#<directory (guil?> ?) ?) ?) ?) ?) ?) ?))
In ice-9/boot-9.scm:
  3935:20  3 (process-use-modules _)
   222:17  2 (map1 (((fibers))))
  3936:31  1 (_ ((fibers)))
   3330:6  0 (resolve-interface (fibers) #:select _ #:hide _ #:prefix ?)

ice-9/boot-9.scm:3330:6: In procedure resolve-interface:
no code for module (fibers)
error: 1.39 process `foo' failed with return value 1.
#v-

Looks like GUILE_LOAD_PATH is not set.

-- 
Olivier Dion
oldiob.dev


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-21 20:08           ` Olivier Dion via
@ 2022-04-21 20:46             ` Ricardo Wurmus
  2022-04-21 22:02               ` Olivier Dion via
  0 siblings, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2022-04-21 20:46 UTC (permalink / raw)
  To: Olivier Dion; +Cc: gwl-devel


Olivier Dion <olivier.dion@polymtl.ca> writes:

> On Thu, 21 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
>>>> This is now fixed with commit
>>>> dceec9ecb9e24252ab9130f7a3626c00b2ff1a68.
>
> I tried this:
>
> process foo
>   packages "guile" "guile-fibers"
>   # /bin/guile {
>     (use-modules (fibers))
>   }


You’re missing “-c”.  If you just use /bin/guile it expects a file name,
just like it does on the command line.  This works fine:

process run
  packages "guile" "guile-fibers"
  # /bin/guile -c {
    (use-modules (fibers))
  }

> Also tried this:
>
> process foo
>   packages "guile" "guile-fibers"
>   procedure
>     . `(begin
>         (use-modules (fibers)))

I haven’t addressed this yet.

What happens here is that we are in fact setting GUILE_LOAD_PATH and
GUILE_LOAD_COMPILED_PATH (as we do for any search path specification
associated with the list of packages), but that has no impact on the
load path of the Guile process used to evaluate the expression.

I’ll investigate this.

-- 
Ricardo


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Guile code snippet
  2022-04-21 20:46             ` Ricardo Wurmus
@ 2022-04-21 22:02               ` Olivier Dion via
  0 siblings, 0 replies; 11+ messages in thread
From: Olivier Dion via @ 2022-04-21 22:02 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: gwl-devel

On Thu, 21 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
> Olivier Dion <olivier.dion@polymtl.ca> writes:
>
>> On Thu, 21 Apr 2022, Ricardo Wurmus <rekado@elephly.net> wrote:
>>>>> This is now fixed with commit
>>>>> dceec9ecb9e24252ab9130f7a3626c00b2ff1a68.
>>
>> I tried this:
>>
>> process foo
>>   packages "guile" "guile-fibers"
>>   # /bin/guile {
>>     (use-modules (fibers))
>>   }
>
>
> You’re missing “-c”.  If you just use /bin/guile it expects a file name,
> just like it does on the command line.  This works fine:
>
> process run
>   packages "guile" "guile-fibers"
>   # /bin/guile -c {
>     (use-modules (fibers))
>   }

Okay I confirm that this indeed work. Thanks!
>
>> Also tried this:
>>
>> process foo
>>   packages "guile" "guile-fibers"
>>   procedure
>>     . `(begin
>>         (use-modules (fibers)))
>
> I haven’t addressed this yet.
>
> What happens here is that we are in fact setting GUILE_LOAD_PATH and
> GUILE_LOAD_COMPILED_PATH (as we do for any search path specification
> associated with the list of packages), but that has no impact on the
> load path of the Guile process used to evaluate the expression.
>
> I’ll investigate this.
>
> -- 
> Ricardo
>
-- 
Olivier Dion
oldiob.dev


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-04-21 22:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20  3:37 Guile code snippet Olivier Dion via
2022-04-20  9:47 ` Ricardo Wurmus
2022-04-20 16:13   ` Olivier Dion via
2022-04-20 16:26     ` Ricardo Wurmus
2022-04-20 16:35       ` Olivier Dion via
2022-04-20 21:21     ` Ricardo Wurmus
2022-04-21 16:30       ` Olivier Dion via
2022-04-21 18:14         ` Ricardo Wurmus
2022-04-21 20:08           ` Olivier Dion via
2022-04-21 20:46             ` Ricardo Wurmus
2022-04-21 22:02               ` Olivier Dion via

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).