Binding symbols in stages

2010-03-06 Thread Hans Aberg
In order to do currying via C++ functions*), I might use something  
like an evaluator that evaluates an unbound symbol to itself. Is that  
possible?


Translated into Scheme code, it corresponds to defining say
  (define add (lambda (x) (lambda (y) (+ x y
by
  (define add1 (lambda (y) (+ x y)))
and then
  (define add (lambda (x) ...))
Thus in two separate steps, where the unbound symbol x in the first  
expression is bound only in the second.


I use now
  scm_eval(scm_list_3(scm_sym_lambda, x, y),  
scm_interaction_environment())

where x is a list of symbols and y an expression.

  Hans

*) See the code at http://math.su.se/~haberg/guile/






Re: Binding symbols in stages

2010-03-06 Thread Andy Wingo
Hi Hans,

On Sat 06 Mar 2010 10:03, Hans Aberg  writes:

>   (define add1 (lambda (y) (+ x y)))
> and then
>   (define add (lambda (x) ...))
> Thus in two separate steps, where the unbound symbol x in the first
> expression is bound only in the second.

If I understand you correctly, this is not possible in normal Scheme. (I
say normal Scheme because you can build your own interpreter for another
kind of Scheme within Guile, one with dynamic binding, say.)

The way to leave a bound identifier unbound is precisely to wrap it in a
closure. For example to "delay binding" of Y and Z in:

  (lambda (x) (+ x y z))

you need wrap the expression in a lambda:

  (lambda (y z)
(lambda (x) (+ x y z)))

Which seems to be what you're trying to get away from, though I don't
know why.

Hope this helps,

Andy
-- 
http://wingolog.org/




Re: Binding symbols in stages

2010-03-06 Thread Hans Aberg

On 6 Mar 2010, at 12:13, Andy Wingo wrote:


 (define add1 (lambda (y) (+ x y)))
and then
 (define add (lambda (x) ...))
Thus in two separate steps, where the unbound symbol x in the first
expression is bound only in the second.


If I understand you correctly, this is not possible in normal Scheme.


I suspected that; thanks for the confirmation.


(I
say normal Scheme because you can build your own interpreter for  
another

kind of Scheme within Guile, one with dynamic binding, say.)


What do you have in your mind here?

The way to leave a bound identifier unbound is precisely to wrap it  
in a

closure. For example to "delay binding" of Y and Z in:

 (lambda (x) (+ x y z))

you need wrap the expression in a lambda:

 (lambda (y z)
   (lambda (x) (+ x y z)))

Which seems to be what you're trying to get away from, though I don't
know why.


I'm Scheme expressions as a part of the interface. So x >>= f  
constructs (lambda (x) f). Now, if I want to create a function, I can  
do that by

  symbol x("x");
  function1 inc = x >>= x + integer(2);
One option is to let the ">>=" operator evaluate the expression, and  
hand that over to "inc", which then will hold a procedure.


But then there is a problem when doing a curried function:
  symbol x("x"), y("y");
  function2 add = x >>= y >>= x + y; //  
Binds to the right.
Then if y >>= x + y evaluates (lambda (y) (+ x y)), one ends up on the  
question I asked for: all attempts to use the symbol x in it will  
produce an unbound variable error.


So suppose I just store the lambda expression produced by ">>=" in the  
function class. Then scm_call_1() etc only acts on procedures. So I  
have to evaluate f(x)

  scm_primitive_eval(scm_list_2(f, x);

One drawback of this approach, I gather, is that the lambda expression  
isn't evaluated into a procedure, which might be slow.


So yet another approach might be to let the function class evaluate  
the expression into a procedure, and when a member f needs to be used  
in an expression, restore it as such by (lambda x' (f x')), where x'  
is an uninterned symbol.


  Hans






Re: Binding symbols in stages

2010-03-06 Thread Hans Aberg

Typos, it should have been for the curried function type:
 symbol x("x"), y("y");
 function1 > add = x >>= y >>= x  
+ y;

 // Binds to the right.

  Hans






(no subject)

2010-03-06 Thread kamal lamta
I have a project which main purpose is to edit the cursor so that the
program can write from right to left (arabic language)

I downloaded the software from the website and the source for windows
version wintexmacs-1.0.5-src.exe .I use microsoft visual studio 2008
after i tried to convert the existing project have been built with
4200 errors and thasn't work,then i saw that there is some
requirements to install the guile library
please i would be very thankful if you send me a detailed information
on how to builth the program.

any information that can help me in my project please .

 thanks-sorry for my bad english---