Re: [racket-users] Re: Naming conventions for private functions

2017-10-13 Thread David Storrs
Cool.  Thank you, Robby and Matthias.



On Fri, Oct 13, 2017 at 9:50 PM, Robby Findler
 wrote:
> If you want to know what the current racket does (not what the
> chez-based one does), then you can "raco make x.rkt" and then "raco
> decompile x.rkt" to see what is going on.
>
> In the cod quoted below, no closures are allocated because all of the
> functions bar, baz, and jaz are eliminated before runtime.
>
> The current compiler doesn't try to do anything with set!, so if you
> changed the program to this one:
>
> #lang racket
>
> (define (foo.1 x)
>   (define (bar) x)
>   (set! bar bar)
>   (bar))
>
> (define (foo.2 x)
>   (define (baz) 8)
>   (define (jaz) x)
>   (set! baz baz)
>   (set! jaz jaz)
>   (println (jaz))
>   (baz))
>
>
> you will see some lambda expressions survive.
>
> Of course, this may not be a bad thing, depending on what the actual
> application itself is doing. And it may be the case that some of those
> with empty closures aren't allocated, depending on various factors.
>
> Robby
>
>
> On Fri, Oct 13, 2017 at 8:19 PM, David Storrs  wrote:
>> On Fri, Oct 13, 2017 at 2:57 PM, Matthias Felleisen
>>  wrote:
>>>
 On Oct 13, 2017, at 2:55 PM, David Storrs  wrote:

 On Fri, Oct 13, 2017 at 2:50 PM, David Storrs  
 wrote:
> Coming from a Perl background, I've long had a convention of naming
> private functions with a leading underscore, e.g. _do-the-thing.  Is
> there a standard Racket convention for this and, if so, what is it?

 Addendum:  I know that I can define functions inside the function for
 which they are the helper, but my understanding is that if I do that
 then the helper function is recompiled every time the parent function
 is executed.

 (define (flurble args)
   (define (helper-func) ...do stuff...)
   (helper-func ...))

 (for ((i 1))
  (flurble i)) ; helper-func will be built 10,000 times, right?
>>>
>>>
>>> No it isn’t recompiled. But the run-time may allocate a closure a second 
>>> time.
>>> Lambda lifting and similar techniques should avoid this but not necessarily 
>>> in
>>> the current compiler.
>>
>>
>> (define (foo x)
>> (for ((i 1))
>> (define (bar) x)
>> (bar)))
>>
>> So bar will be allocated 10,000 times in the above?  How about baz and
>> jaz in the below?
>>
>>
>> (define (foo x)
>>   (define (baz) 8)
>>   (define (jaz) x)
>>   (println (jaz))
>>   (baz))
>>
>> (for ((i 1))
>>   (foo 7))
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Naming conventions for private functions

2017-10-13 Thread Robby Findler
If you want to know what the current racket does (not what the
chez-based one does), then you can "raco make x.rkt" and then "raco
decompile x.rkt" to see what is going on.

In the cod quoted below, no closures are allocated because all of the
functions bar, baz, and jaz are eliminated before runtime.

The current compiler doesn't try to do anything with set!, so if you
changed the program to this one:

#lang racket

(define (foo.1 x)
  (define (bar) x)
  (set! bar bar)
  (bar))

(define (foo.2 x)
  (define (baz) 8)
  (define (jaz) x)
  (set! baz baz)
  (set! jaz jaz)
  (println (jaz))
  (baz))


you will see some lambda expressions survive.

Of course, this may not be a bad thing, depending on what the actual
application itself is doing. And it may be the case that some of those
with empty closures aren't allocated, depending on various factors.

Robby


On Fri, Oct 13, 2017 at 8:19 PM, David Storrs  wrote:
> On Fri, Oct 13, 2017 at 2:57 PM, Matthias Felleisen
>  wrote:
>>
>>> On Oct 13, 2017, at 2:55 PM, David Storrs  wrote:
>>>
>>> On Fri, Oct 13, 2017 at 2:50 PM, David Storrs  
>>> wrote:
 Coming from a Perl background, I've long had a convention of naming
 private functions with a leading underscore, e.g. _do-the-thing.  Is
 there a standard Racket convention for this and, if so, what is it?
>>>
>>> Addendum:  I know that I can define functions inside the function for
>>> which they are the helper, but my understanding is that if I do that
>>> then the helper function is recompiled every time the parent function
>>> is executed.
>>>
>>> (define (flurble args)
>>>   (define (helper-func) ...do stuff...)
>>>   (helper-func ...))
>>>
>>> (for ((i 1))
>>>  (flurble i)) ; helper-func will be built 10,000 times, right?
>>
>>
>> No it isn’t recompiled. But the run-time may allocate a closure a second 
>> time.
>> Lambda lifting and similar techniques should avoid this but not necessarily 
>> in
>> the current compiler.
>
>
> (define (foo x)
> (for ((i 1))
> (define (bar) x)
> (bar)))
>
> So bar will be allocated 10,000 times in the above?  How about baz and
> jaz in the below?
>
>
> (define (foo x)
>   (define (baz) 8)
>   (define (jaz) x)
>   (println (jaz))
>   (baz))
>
> (for ((i 1))
>   (foo 7))
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Naming conventions for private functions

2017-10-13 Thread Matthias Felleisen

> On Oct 13, 2017, at 9:19 PM, David Storrs  wrote:
> 
> On Fri, Oct 13, 2017 at 2:57 PM, Matthias Felleisen
>  wrote:
>> 
>>> On Oct 13, 2017, at 2:55 PM, David Storrs  wrote:
>>> 
>>> On Fri, Oct 13, 2017 at 2:50 PM, David Storrs  
>>> wrote:
 Coming from a Perl background, I've long had a convention of naming
 private functions with a leading underscore, e.g. _do-the-thing.  Is
 there a standard Racket convention for this and, if so, what is it?
>>> 
>>> Addendum:  I know that I can define functions inside the function for
>>> which they are the helper, but my understanding is that if I do that
>>> then the helper function is recompiled every time the parent function
>>> is executed.
>>> 
>>> (define (flurble args)
>>>  (define (helper-func) ...do stuff...)
>>>  (helper-func ...))
>>> 
>>> (for ((i 1))
>>> (flurble i)) ; helper-func will be built 10,000 times, right?
>> 
>> 
>> No it isn’t recompiled. But the run-time may allocate a closure a second 
>> time.
>> Lambda lifting and similar techniques should avoid this but not necessarily 
>> in
>> the current compiler.
> 
> 
> (define (foo x)
>(for ((i 1))
>(define (bar) x)
>(bar)))
> 
> So bar will be allocated 10,000 times in the above?  How about baz and
> jaz in the below?


This kind of situation is covered by ‘lightweight closure’ conversion, 
which we added in the late 90s and should still be there. Note how 
all instances of bar are identical. No need to re-allocate. 



> 
> 
> (define (foo x)
>  (define (baz) 8)
>  (define (jaz) x)
>  (println (jaz))
>  (baz))
> 
> (for ((i 1))
>  (foo 7))

Again, baz is covered trivially. 

Only a whole-program analysis can confirm that foo is applied to only 7 
and therefor jaz is the same closure on every call to foo. 

;; - - - 

Note that programs can use eq? to compare closures. I am ignoring this aspect. 




-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Naming conventions for private functions

2017-10-13 Thread David Storrs
On Fri, Oct 13, 2017 at 2:57 PM, Matthias Felleisen
 wrote:
>
>> On Oct 13, 2017, at 2:55 PM, David Storrs  wrote:
>>
>> On Fri, Oct 13, 2017 at 2:50 PM, David Storrs  wrote:
>>> Coming from a Perl background, I've long had a convention of naming
>>> private functions with a leading underscore, e.g. _do-the-thing.  Is
>>> there a standard Racket convention for this and, if so, what is it?
>>
>> Addendum:  I know that I can define functions inside the function for
>> which they are the helper, but my understanding is that if I do that
>> then the helper function is recompiled every time the parent function
>> is executed.
>>
>> (define (flurble args)
>>   (define (helper-func) ...do stuff...)
>>   (helper-func ...))
>>
>> (for ((i 1))
>>  (flurble i)) ; helper-func will be built 10,000 times, right?
>
>
> No it isn’t recompiled. But the run-time may allocate a closure a second time.
> Lambda lifting and similar techniques should avoid this but not necessarily in
> the current compiler.


(define (foo x)
(for ((i 1))
(define (bar) x)
(bar)))

So bar will be allocated 10,000 times in the above?  How about baz and
jaz in the below?


(define (foo x)
  (define (baz) 8)
  (define (jaz) x)
  (println (jaz))
  (baz))

(for ((i 1))
  (foo 7))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Naming conventions for private functions

2017-10-13 Thread David Storrs
On Fri, Oct 13, 2017 at 2:59 PM, Robby Findler
 wrote:
> Also: if you just don't `provide` a function from a module, then it
> cannot be used outside. No naming conventions necessary.
>

Sure, but the underscore helps me know at a glance what I'm looking
at, whether it's safe to make a breaking change to a function, etc.

> Robby
>
> On Fri, Oct 13, 2017 at 1:57 PM, Matthias Felleisen
>  wrote:
>>
>>> On Oct 13, 2017, at 2:55 PM, David Storrs  wrote:
>>>
>>> On Fri, Oct 13, 2017 at 2:50 PM, David Storrs  
>>> wrote:
 Coming from a Perl background, I've long had a convention of naming
 private functions with a leading underscore, e.g. _do-the-thing.  Is
 there a standard Racket convention for this and, if so, what is it?
>>>
>>> Addendum:  I know that I can define functions inside the function for
>>> which they are the helper, but my understanding is that if I do that
>>> then the helper function is recompiled every time the parent function
>>> is executed.
>>>
>>> (define (flurble args)
>>>   (define (helper-func) ...do stuff...)
>>>   (helper-func ...))
>>>
>>> (for ((i 1))
>>>  (flurble i)) ; helper-func will be built 10,000 times, right?
>>
>>
>> No it isn’t recompiled. But the run-time may allocate a closure a second 
>> time.
>> Lambda lifting and similar techniques should avoid this but not necessarily 
>> in
>> the current compiler.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Naming conventions for private functions

2017-10-13 Thread Eric Eide
Robby Findler  writes:

> Also: if you just don't `provide` a function from a module, then it
> cannot be used outside. No naming conventions necessary.

But the no-naming convention is necessary.
:-).

-- 
---
Eric Eide   . University of Utah School of Computing
http://www.cs.utah.edu/~eeide/ . +1 (801) 585-5512 voice, +1 (801) 581-5843 FAX

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Naming conventions for private functions

2017-10-13 Thread Robby Findler
Also: if you just don't `provide` a function from a module, then it
cannot be used outside. No naming conventions necessary.

Robby

On Fri, Oct 13, 2017 at 1:57 PM, Matthias Felleisen
 wrote:
>
>> On Oct 13, 2017, at 2:55 PM, David Storrs  wrote:
>>
>> On Fri, Oct 13, 2017 at 2:50 PM, David Storrs  wrote:
>>> Coming from a Perl background, I've long had a convention of naming
>>> private functions with a leading underscore, e.g. _do-the-thing.  Is
>>> there a standard Racket convention for this and, if so, what is it?
>>
>> Addendum:  I know that I can define functions inside the function for
>> which they are the helper, but my understanding is that if I do that
>> then the helper function is recompiled every time the parent function
>> is executed.
>>
>> (define (flurble args)
>>   (define (helper-func) ...do stuff...)
>>   (helper-func ...))
>>
>> (for ((i 1))
>>  (flurble i)) ; helper-func will be built 10,000 times, right?
>
>
> No it isn’t recompiled. But the run-time may allocate a closure a second time.
> Lambda lifting and similar techniques should avoid this but not necessarily in
> the current compiler.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Naming conventions for private functions

2017-10-13 Thread David Storrs
On Fri, Oct 13, 2017 at 2:50 PM, David Storrs  wrote:
> Coming from a Perl background, I've long had a convention of naming
> private functions with a leading underscore, e.g. _do-the-thing.  Is
> there a standard Racket convention for this and, if so, what is it?

Addendum:  I know that I can define functions inside the function for
which they are the helper, but my understanding is that if I do that
then the helper function is recompiled every time the parent function
is executed.

(define (flurble args)
   (define (helper-func) ...do stuff...)
   (helper-func ...))

(for ((i 1))
  (flurble i)) ; helper-func will be built 10,000 times, right?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.