or values bug?

2011-12-05 Thread rixed
Is it normal that this:

(or (values 'a 'b) 'c)

returns two values ('a and 'b) while this:

(or (values 'a (lambda (port) #f)) 'c)

returns only one ('a)?
Isn't it a bug?




Re: Guile on Zile, module questions

2011-12-05 Thread Ludovic Courtès
Hi Mike!

Mike Gran  skribis:

> Over the USA holiday I started looking at the last C version of
> Zile, which has its own toy Lisp interpreter.  (Zile also
> comes in a new Lua version!)  I looks like it would be simple to
> strip out that Zile Lisp and replace it with Guile Scheme. 
> But I don't think anyone has tried it.

This sounds great!  Another competitor for Gano and Guile-Emacs!  ;-)

Where’s the source?  :-)

> Zile has two scopes.
> 1) a Zile scope
> 2) a buffer-specific scope

You might want to check the crazy things BT Templeton did to handle
that:

  http://www.gnu.org/ghm/2011/paris/slides/bt-templeton-guile-emacs.pdf

(You might need additional input from him, though.  ;-))

> As far as I can tell, I should use 'module-obarray' to get
> all the bindings for the buffer-specific module and I should
> look at '%module-public-interface' to get the list of exported
> functions and vars in the top Zile module.

Note that you should use ‘module-public-interface’ instead of referring
to the ‘%module-public-interface’ binding.

Here’s an example:

  (hash-fold (lambda (k v r) (cons k r))
 '()
 (module-obarray (module-public-interface the-root-module)))

There’s also ‘module-for-each’:

  (module-for-each (lambda (b v)
 (format #t "variable `~a' has value `~a'~%" b
 (variable-ref v)))
   (resolve-interface '(ice-9 q)))

Looking forward to using this new Zile.  :-)

Ludo’.




Re: getopt-long

2011-12-05 Thread Ludovic Courtès
Hi Andrew,

Andrew Horton  skribis:

> Recently I needed to be able to recognize multiple use of an option
> when using getopt-long.

This would be an incompatible change, so I’d rather not do it.

However, I’d recommend using SRFI-37: it supports multiple occurrences
of an option, and has a nicer interface IMO.

Thanks,
Ludo’.




Re: propagating a coding setting across source files

2011-12-05 Thread Ludovic Courtès
Hi!

Mike Gran  skribis:

> I'm pretty sure that, for 2.0.x at least, if you don't
> specify an encoding, it presumes iso-8859-1 as the default.

No, UTF-8 is the default (info "(guile) Compilation").

Thanks,
Ludo’.




Re: or values bug?

2011-12-05 Thread Ludovic Courtès
Hi Cédric,

ri...@happyleptic.org skribis:

> Is it normal that this:
>
> (or (values 'a 'b) 'c)
>
> returns two values ('a and 'b)

This one gets optimized by peval:

  scheme@(guile-user)> ,optimize (or (values 1 2) 'b)
  $6 = (values 1 2)

That the second value isn’t truncated is a bug (see below.)

> while this:
>
> (or (values 'a (lambda (port) #f)) 'c)
>
> returns only one ('a)?

This one doesn’t:

  scheme@(guile-user)> ,optimize (or (values 1 (lambda () #t)) 'b)
  $5 = (begin
(letrec*
  ()
  (let ((#{t 1263}# (values 1 (lambda () #t
(if #{t 1263}# #{t 1263}# 'b

The ‘let’, which leads to the second value being ignored, comes from the
definition of ‘or’:

  (define-syntax or
(syntax-rules ()
  ((_) #f)
  ((_ x) x)
  ((_ x y ...) (let ((t x)) (if t t (or y ...))

It’s normal that the second value is ignored because ‘or’ expects
expressions returning one value.

In theory, peval should really optimize the first form to 1, instead of
multiple-values, but I think it loses information about the context
somewhere.

Namely, when partial-evaluating  forms, I think it should:

   (let* ((vars (map (compose truncate lookup-var) gensyms))
  ...)
 ...)

where ‘truncate’ discards all values but the first of a 
form.

Andy?

Thanks,
Ludo’.




Re: getopt-long

2011-12-05 Thread Thien-Thi Nguyen
() Andrew Horton 
() Thu, 01 Dec 2011 11:40:40 +

   recognize multiple use of an option when using getopt-long.

Guile 1.4.x extended (ice-9 getopt-long) to handle multiple occurances.
Here is an excerpt from (info "(guile) getopt-long Reference"):

  `(merge-multiple? BOOL)'
If BOOL is `#t' and the `value' property is not `#f', all
(one or multiple) occurrances are merged into a list with
order retained.  If `#f', each instance of the option results
in a separate entry in the resulting alist.

Subsequently, this rat jumped to the non-(not-yet?)-sinking ttn-do
as module ‘(ttn-do zzz bamboozled)’.  More info online:

http://www.gnuvola.org/software/guile/doc/getopt_002dlong-Reference.html
http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zzz-bamboozled

I think it would be cool if this were to find berth in official Guile.



Re: getopt-long

2011-12-05 Thread Andrew Horton
That would do the trick. I've also thought that a (help "...") for
each option would also be useful, which could append the string for
each arg to the "--help" option text automatically (somehow).

On 5 December 2011 18:35, Thien-Thi Nguyen  wrote:
> () Andrew Horton 
> () Thu, 01 Dec 2011 11:40:40 +
>
>   recognize multiple use of an option when using getopt-long.
>
> Guile 1.4.x extended (ice-9 getopt-long) to handle multiple occurances.
> Here is an excerpt from (info "(guile) getopt-long Reference"):
>
>  `(merge-multiple? BOOL)'
>        If BOOL is `#t' and the `value' property is not `#f', all
>        (one or multiple) occurrances are merged into a list with
>        order retained.  If `#f', each instance of the option results
>        in a separate entry in the resulting alist.
>
> Subsequently, this rat jumped to the non-(not-yet?)-sinking ttn-do
> as module ‘(ttn-do zzz bamboozled)’.  More info online:
>
> http://www.gnuvola.org/software/guile/doc/getopt_002dlong-Reference.html
> http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zzz-bamboozled
>
> I think it would be cool if this were to find berth in official Guile.



Re: getopt-long

2011-12-05 Thread Andy Wingo
On Mon 05 Dec 2011 18:14, l...@gnu.org (Ludovic Courtès) writes:

> However, I’d recommend using SRFI-37: it supports multiple occurrences
> of an option, and has a nicer interface IMO.

I like it too, but I use both, and if we can make getopt-long more
useful, there doesn't seem to be any harm in that.

Andy
-- 
http://wingolog.org/



Re: getopt-long

2011-12-05 Thread Andy Wingo
On Mon 05 Dec 2011 19:35, Thien-Thi Nguyen  writes:

> Guile 1.4.x extended (ice-9 getopt-long) to handle multiple occurances.
> Here is an excerpt from (info "(guile) getopt-long Reference"):
>
>   `(merge-multiple? BOOL)'
> If BOOL is `#t' and the `value' property is not `#f', all
> (one or multiple) occurrances are merged into a list with
> order retained.  If `#f', each instance of the option results
> in a separate entry in the resulting alist.

That would be a compatible change, no?  A patch would be gladly accepted
:)

Regards,

Andy
-- 
http://wingolog.org/



Re: or values bug?

2011-12-05 Thread Andy Wingo
On Mon 05 Dec 2011 18:40, l...@gnu.org (Ludovic Courtès) writes:

>   scheme@(guile-user)> ,optimize (or (values 1 2) 'b)
>   $6 = (values 1 2)
>
> That the second value isn’t truncated is a bug (see below.)

Indeed.

>(let* ((vars (map (compose truncate lookup-var) gensyms))
>   ...)
>  ...)

Better to truncate when adding variables to all expand-time
environments, I would think, in the form of `(cut make-primcall #f
'values <>)'.

Andy
-- 
http://wingolog.org/



Re: or values bug?

2011-12-05 Thread Andy Wingo
On Mon 05 Dec 2011 21:57, Andy Wingo  writes:

>>(let* ((vars (map (compose truncate lookup-var) gensyms))
>>   ...)
>>  ...)
>
> Better to truncate when adding variables to all expand-time
> environments, I would think, in the form of `(cut make-primcall #f
> 'values <>)'.

Rather, something like:

   (define (truncate x)
 (match x
   (() x)
   ;; similar provably singly-valued cases here
   (else (make-primcall #f 'values (list x)

Andy
-- 
http://wingolog.org/



Re: getopt-long

2011-12-05 Thread Ludovic Courtès
Hi,

Andy Wingo  skribis:

> On Mon 05 Dec 2011 19:35, Thien-Thi Nguyen  writes:
>
>> Guile 1.4.x extended (ice-9 getopt-long) to handle multiple occurances.
>> Here is an excerpt from (info "(guile) getopt-long Reference"):
>>
>>   `(merge-multiple? BOOL)'
>> If BOOL is `#t' and the `value' property is not `#f', all
>> (one or multiple) occurrances are merged into a list with
>> order retained.  If `#f', each instance of the option results
>> in a separate entry in the resulting alist.
>
> That would be a compatible change, no?

Indeed, that would be OK.

Thanks,
Ludo’.




Re: or values bug?

2011-12-05 Thread rixed

Thank you to both of you for the explanations and for looking 
for a solution so quickly.
Anyway, I changed my code to not use this evil multiple value feature and I
think I will keep away from this. Returning a list seams so much natural.

Do you need me actualy fill a bugreport?