definition in expression context, where definitions are not allowed

2015-10-11 Thread Arne Babenhauserheide
Hi,

I’m repeatedly stumbling over the restrictions where to use define. Here’s a 
minimal example:

(define (hello who)
  (display "Hello ")
  (define (world who)
(display who))
  (world who)
  (display "!")
  (newline))

This throws a Syntax error: …definition in expression context, where
definitions are not allowed, in form (define (world who) (display
who))

And though I know that there are reasons for this, it just feels wrong
to be in the language which removes restrictions for writing great
languages and then seeing such a complication.

This works just fine - keeping all the information in the definition -
when I rewrite it to

(define (hello who)
  (display "Hello ")
  (let ((world (lambda (who) (display who
(world who)
(display "!")
(newline)))

So why isn’t that done automatically? Why does Guile not just do this
transformation with an information message that the define was changed
to a let? It already detects the situation, why can’t it make it work?

In other words: Is the optimization allowed by this worth the
additional complexity of the language?

Or am I missing something else which is enabled by this limitation?

Best wishes,
Arne


signature.asc
Description: This is a digitally signed message part.


Re: definition in expression context, where definitions are not allowed

2015-10-11 Thread Taylan Ulrich Bayırlı/Kammer
Arne Babenhauserheide  writes:

> (define (hello who)
>   (display "Hello ")
>   (define (world who)
> (display who))
>   (world who)
>   (display "!")
>   (newline))

Let's look at a different example first, which works with the current
semantics:

  (let ()
(define (odd? n) (if (zero? n) #f (even? (- n 1
(define (even? n) (if (zero? n) #t (odd? (- n 2
(even? 42))

That works because the internal definitions become 'letrec*' so they may
refer to each other, i.e. 'odd?' can refer to 'even?' in its body,
before 'even?' is really defined.

If your example also worked, than with the combination of the above,
users might ultimately also expect this to work:

  (let ()
(define (hello)
  (display "Hello ")
  (world)
  (display "!")
  (newline))
(display "Goodbye Eden, ")
(define (world)
  (display "World"))
(hello))

Just like in the top-level.  But that would require making the whole
procedure body a big 'letrec*' expression.  If I'm not mistaken that's
exactly what JavaScript does, called "var hoisting," where all variables
declared anywhere in a function become bound to a special 'undefined'
value at the beginning of the function, and these don't behave exactly
as undefined variables either.  In Guile too, variables "bound but not
defined yet" as created by 'letrec*' aren't checked for invalid access
because it would put overhead on every variable reference.  So that
would end up giving us those weird semantics as known from JS.

(IIRC, "strict mode" JS only allows variable declarations at the
beginning of a function body, just like internal defines in Scheme.)

Or maybe my example was a bit contrived, and/or we can teach users that
they should "group together" definitions that refer to each other, and
have those groups turn into nested 'letrec*' expressions (similar to
your proposal, just using 'letrec*' when there's multiple adjacent
'define' forms).  But that makes things more and more complicated, and
by the time we taught users that we could have probably just taught them
the simpler rule that internal 'define' forms may only appear at the
beginning of a body.

Does that make sense?

Taylan



Fwd: Re: definition in expression context, where definitions are not allowed

2015-10-11 Thread Arne Babenhauserheide
Hi David,

Thank you for answering!

May I send my reply to guile-devel?

Am Sonntag, 11. Oktober 2015, 09:58:59 schrieb David Kastrup:
> > Or am I missing something else which is enabled by this limitation?
> 
> A function defined with `define' may call a function defined in a
> _following_ `define'.  How do you make that work when a statement
> in-between can already call the first function?

So this is a guarantee that all defines in a block of defines can call
each other?

I now looked it up in r7rs small.[1]

> Definitions can occur at the beginning of a body (that
> is, the body of a lambda, let, let*, letrec, letrec*,
> let-values, let*-values, let-syntax, letrec-syntax,
> parameterize, guard, or case-lambda).

> An expanded body containing internal definitions can al-
> ways be converted into a completely equivalent letrec*
> expression.

So essentially this is just explicit scoping, as with let. And let
proved to me that it works better than just assigning anywhere
(because it doesn’t have a large overhead).

So I think what threw me off is mainly the error message: 

> definition in expression context, where definitions are not allowed

This does not tell me how I can do what I intended to. “all
definitions must be at the beginning of the body. You can for example
create a new scope with let ().”

Best wishes,
Arne

[1]: http://trac.sacrideo.us/wg/wiki/R7RSHomePage
 http://trac.sacrideo.us/wg/raw-attachment/wiki/WikiStart/r7rs.pdf
 5.3.2, page 26


signature.asc
Description: This is a digitally signed message part.


Re: New logo and website design proposal

2015-10-11 Thread Ludovic Courtès
Luis Felipe López Acevedo  skribis:

> On 2015-10-10 12:24, Thompson, David wrote:
>> On Fri, Oct 9, 2015 at 6:24 PM, Luis Felipe López Acevedo
>>  wrote:

[...]

>>> I just finished an implementation of the new website. You can grab
>>> a copy of
>>> the built site from here:
>>>
>>>   https://bitbucket.org/sirgazil/dnd/downloads/guile-website-20151009.tar.gz
>>>
>>> To try it out:
>>>
>>>$ cd path/to/guile-website-mmdd
>>>$ python3 -m http.server# couldn't find a equivalent
>>> in Guile

This is perfect!

Andy, Mark: WDYT?  I suppose that the changes, if any, will be fine
tuning, so no worries.

>> Maybe Guile core could use a basic static file web server?

Yes, that would be nice.

>>> Then visit the website at .
>>
>> It looks great!  Thanks for sharing!  Now, who can help you make the
>> final edits and get it live?
>
> Thanks, David, and thanks Amirouche and Chris :)
>
> In the meantime, I updated the illustration that was pending, and
> added AGPL license to Scheme code, and CC-BY-SA 4.0 License to
> graphics to save you some edition.
>
> I guess the next step is to add the source to a Git repo in Savannah,
> and do the rest there.

I’ve requested the creation of a new Git repo:

  https://savannah.gnu.org/support/?108907

> Let me know if you need anything else :)

If you do not want to do the conversion to SXML (or Haunt?), I think
Mathieu Lirzin had offered to help.  Anyway, let us know if *you* need
anything else.  ;-)

Thank you!

Ludo’.



Re: New logo and website design proposal

2015-10-11 Thread Luis Felipe López Acevedo

On 2015-10-11 15:11, l...@gnu.org wrote:

Luis Felipe López Acevedo  skribis:


On 2015-10-10 12:24, Thompson, David wrote:

On Fri, Oct 9, 2015 at 6:24 PM, Luis Felipe López Acevedo
 wrote:


[...]


I just finished an implementation of the new website. You can grab
a copy of
the built site from here:

  
https://bitbucket.org/sirgazil/dnd/downloads/guile-website-20151009.tar.gz


To try it out:

   $ cd path/to/guile-website-mmdd
   $ python3 -m http.server# couldn't find a equivalent
in Guile


This is perfect!

Andy, Mark: WDYT?  I suppose that the changes, if any, will be fine
tuning, so no worries.


Maybe Guile core could use a basic static file web server?


Yes, that would be nice.


Then visit the website at .


It looks great!  Thanks for sharing!  Now, who can help you make the
final edits and get it live?


Thanks, David, and thanks Amirouche and Chris :)

In the meantime, I updated the illustration that was pending, and
added AGPL license to Scheme code, and CC-BY-SA 4.0 License to
graphics to save you some edition.

I guess the next step is to add the source to a Git repo in Savannah,
and do the rest there.


I’ve requested the creation of a new Git repo:

  https://savannah.gnu.org/support/?108907


Let me know if you need anything else :)


If you do not want to do the conversion to SXML (or Haunt?), I think
Mathieu Lirzin had offered to help.  Anyway, let us know if *you* need
anything else.  ;-)

Thank you!

Ludo’.


No need for conversion, Ludovic, the source is pure Guile Scheme (I did 
my homework):


https://bitbucket.org/sirgazil/guile-website

I just used Python simple server for testing the built HTML :)


--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.org/