Robby Findler | 1 Jun 2007 01:08
Favicon

Re: cost of closure?

On 5/31/07, YC <yinso.chen@...> wrote:
> Am I inferring correctly that you are saying closure consumes a constant
> factor of memory over struct, but otherwise doesn't necessarily hold onto
> unnecessarily references from the stack?

Right.

> Any other way besides closure & struct to create opaque compound value
> objects?

The way we think of it: all compound values are structs at one level
or another. You just may or may not have access to the inspector to
see the fields. So ... no. :)

> Thanks,
> yinso
>
>
> On 5/31/07, Robby Findler <robby@...> wrote:
> > The size of a closure is proportional to the number of free variables
> > in the function. A struct with an equivalent number of slots uses less
> > memory, however.
> >
> > Robby
> >
> > On 5/31/07, YC < yinso.chen@...> wrote:
> > >
> > > On 5/31/07, Carl Eastlund <cce@...> wrote:
> > > > > In principle, a closure is essentially a struct.  All that needs to
> be
(Continue reading)

YC | 1 Jun 2007 01:31
Picon
Gravatar

Re: cost of closure?

Hi Jens -

thanks for the great explanation about how Scheme works in general, as well as the link (I'm reading through right now).  I would assume that using closure as compound value object is one of the perceived uses that have been thought of and that a good compiler would put some work toward making sure it can efficiently support the uses, but I also understand that completely depends on the implementation.

While it's unclear for me what model PLT Scheme uses for structs - Robby alluded to that closures is only a constant factor over struct from memory consumption.

If there is indeed an upper bound somewhere for closure objects that would be good to know too ;)

Thanks,
yinso

On 5/31/07, Jens Axel Søgaard <jensaxel-2WZPQIjRgZTk1uMJSBkQmQ@public.gmane.org> wrote:
YC wrote:

> I've heard that Scheme
> doesn't keep variables on the stack, but want to verify.

The explanation is a little involved. First the
concept of call stack. Consider:

   (define (f x) (g (+ x 1))
   (define (g y) (h (+ y 2))
   (define (h z) (+ x 3))
   (f 0)

Conceptually f calls g, which calls h. So we have
a stack of functions calls here. In most languages
the conceptually call stack is implemented as an
actual stack.

That strategy can't be used naïvely with Scheme.
due to call-with-current-continuation. The
problem is that call/cc allows a function to
return more than once - and thus conceptually
you get a call *tree* instead of a call stack.

In a simple Scheme implementations the tree is
represented as (you guessed it) a tree stored
in the normal garbage collected heap.

However it is possible to use a stack to store the
current branch of the call tree and then do
some trickery when control transfers to another
branch [actually a little trickery is needed prior
to this too].

In short, you can't say "Scheme doesn't keep variables
on the stack" because some implementations do and
others don't-

The canonical [I believe] reference is:

   "Three Implementation Models for Scheme"
   by R. Kent Dybvig.

It is very well-written and explains everything
in detail. See especially chapter 3 and 4.

--
Jens Axel Søgaard

_________________________________________________
  For list-related administrative tasks:
   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
Matthew Flatt | 1 Jun 2007 01:36
Picon
Favicon
Gravatar

Re: make-file-or-directory-link with relative path

At Thu, 31 May 2007 23:09:56 +0100, John Kozak wrote:
> Calling (make-file-or-directory-link <relative-path> <link>) 
> creates a non-relative link, with <relative-path> resolved within the
> CWD.

In version 352 and earlier, right?

>  Surely this is wrong, and it should just create a relative link?

Yes --- fixed in v360 and later.

Matthew

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Matthew Flatt | 1 Jun 2007 01:36
Picon
Favicon
Gravatar

Re: cost of closure?

At Thu, 31 May 2007 16:31:28 -0700, YC wrote:
> While it's unclear for me what model PLT Scheme uses for structs - Robby
> alluded to that closures is only a constant factor over struct from memory
> consumption.

I think that constant factor should be between 0 and 1 pointer,
depending on whether the closure refers to top-level bindings or module
top-level bindings (other than things that are built into MzScheme, in
which case the reference is inlined instead of kept in the closure).

Otherwise, a closure has a pointer to its code, and a struct has a
pointer to it's type descriptor, so those balance; each field and
captured bindings take the same amount of space.

Matthew

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Danny Yoo | 1 Jun 2007 01:45
Gravatar

Using prepared statements

>>  Are there static type systems that can protect against, e.g., SQL
>>  injection?
>
> I have always wondered why people aren't using Prepare more. Is it too 
> expensive? Or is the reason perhaps that people are using languages 
> without closures?

I think it's ignorance.

When I was doing Python programming, I saw newcomers work with the Python 
DBI and almost always not use prepared statements but rather string 
concatenate.  That's what their teacher told them to do.  And even people 
who should know better can propagate this problem.  Here's one example:

     http://mail.python.org/pipermail/tutor/2003-April/022010.html

I saw the same thing with many Java programmers: I rarely saw use of 
prepareStatement(), and even when I saw people using it, the code would 
completely miss the point of prepareStatement(); I'd see code like:

     stmt = conn.prepareStatement("insert into article (title) values ('" +
                                  title + "')");
     stmt.executeQuery();

which made me laugh and cry at the same time.

I'm very glad that Hans's SQLID interface includes support for prepared 
statements.  I would like to see it highlighted more vividly in the 
documentation.  As it is, it's just a quick mention in:

http://www.elemental-programming.org/sqli.html#_code__sqli_query_sqli_handle_query___args____boolean__code_

as a set of optional arguments passed to the "query" method.
_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

YC | 1 Jun 2007 01:45
Picon
Gravatar

Re: cost of closure?



On 5/31/07, Robby Findler <robby-kRQskCh0V2e+fvpajLlQkQ@public.gmane.org> wrote:
On 5/31/07, YC <yinso.chen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Am I inferring correctly that you are saying closure consumes a constant
> > factor of memory over struct, but otherwise doesn't necessarily hold onto
> > unnecessarily references from the stack?

> Right.

Thanks.

> > Any other way besides closure & struct to create opaque compound value
> > objects?

> The way we think of it: all compound values are structs at one level
> or another. You just may or may not have access to the inspector to
> see the fields. So ... no. :)

Out of curiosity - does PLT scheme actually use struct as the fundamental compound type, i.e. implement closure/etc on top of struct.  I like structs but have problem with 1) making it anonymous and 2) that make-struct-type is cumbersome if define-struct along doesn't cut it.

Thanks,
yinso



_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
YC | 1 Jun 2007 01:46
Picon
Gravatar

Re: cost of closure?


On 5/31/07, Matthew Flatt <mflatt-sDh8Nw2yj/+Vc3sceRu5cw@public.gmane.org> wrote:
> At Thu, 31 May 2007 16:31:28 -0700, YC wrote:
> > While it's unclear for me what model PLT Scheme uses for structs - Robby
> > alluded to that closures is only a constant factor over struct from memory
> > consumption.

> I think that constant factor should be between 0 and 1 pointer,
> depending on whether the closure refers to top-level bindings or module
> top-level bindings (other than things that are built into MzScheme, in
> which case the reference is inlined instead of kept in the closure).

> Otherwise, a closure has a pointer to its code, and a struct has a
> pointer to it's type descriptor, so those balance; each field and
> captured bindings take the same amount of space.

That's not bad at all... ;)

Thanks,
yinso

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
Matthew Flatt | 1 Jun 2007 01:49
Picon
Favicon
Gravatar

Re: cost of closure?

At Thu, 31 May 2007 16:45:25 -0700, YC wrote:
> Out of curiosity - does PLT scheme actually use struct as the fundamental
> compound type, i.e. implement closure/etc on top of struct. 

The way I think about it, everything is a struct, but some things use a
special-case representation because they're important enough. (The
extreme case is a fixnum).

But an equally valid answer would be: no, not all compound types use
the same representation as values from a struct constructor.

> I like structs
> but have problem with 1) making it anonymous and 2) that make-struct-type is
> cumbersome if define-struct along doesn't cut it.

Agreed. A more complete `define-struct' form is high on the list of
additions for version 4.0.

Matthew

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Ryan Culpepper | 1 Jun 2007 02:07
Favicon

Re: cost of closure?

On Fri, 2007-06-01 at 07:49 +0800, Matthew Flatt wrote:
> At Thu, 31 May 2007 16:45:25 -0700, YC wrote:
> > Out of curiosity - does PLT scheme actually use struct as the fundamental
> > compound type, i.e. implement closure/etc on top of struct. 
> 
> The way I think about it, everything is a struct, but some things use a
> special-case representation because they're important enough. (The
> extreme case is a fixnum).
> 
> But an equally valid answer would be: no, not all compound types use
> the same representation as values from a struct constructor.
> 
> > I like structs
> > but have problem with 1) making it anonymous and 2) that make-struct-type is
> > cumbersome if define-struct along doesn't cut it.
> 
> Agreed. A more complete `define-struct' form is high on the list of
> additions for version 4.0.

Speaking of which, check out 'define-struct*' in 
(planet "struct.ss" ("ryanc" "macros.plt" 1)).

Ryan

> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

YC | 1 Jun 2007 02:11
Picon
Gravatar

Re: Using prepared statements

One of the ignorances has to do with unfamiliarity with set programming plus premature optimization.

Many production SQL code I've seen use concatenations to generate dynamic sql statements for creating different where clauses and return different columns, which of course leads to SQL injection problems (as well as difficult to debug SQL query/stored procedures).  Often the developers in charge (even experienced ones) don't know how to write one single sql statement to represent the "different" sql statements (even if they know how to do so they rather use dynamic SQL to write more compact thus "optimized" statements).  The same developer often is more comfortable write cursors and loops rather than using selects appropriately.


On 5/31/07, Danny Yoo <dyoo-kCM0ysTr5uA3uPMLIKxrzw@public.gmane.org > wrote:
I think it's ignorance.

When I was doing Python programming, I saw newcomers work with the Python
DBI and almost always not use prepared statements but rather string
concatenate.  That's what their teacher told them to do.  And even people
who should know better can propagate this problem.  Here's one example:

     http://mail.python.org/pipermail/tutor/2003-April/022010.html

I saw the same thing with many Java programmers: I rarely saw use of
prepareStatement(), and even when I saw people using it, the code would
completely miss the point of prepareStatement(); I'd see code like:

     stmt = conn.prepareStatement("insert into article (title) values ('" +
                                  title + "')");
     stmt.executeQuery();

which made me laugh and cry at the same time.



I'm very glad that Hans's SQLID interface includes support for prepared
statements.  I would like to see it highlighted more vividly in the
documentation.  As it is, it's just a quick mention in:

http://www.elemental-programming.org/sqli.html#_code__sqli_query_sqli_handle_query___args____boolean__code_

as a set of optional arguments passed to the "query" method.
_________________________________________________
  For list-related administrative tasks:
   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Gmane