[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Gensym" in Typol




In article <12818@sophia.inria.fr>, banerjee@cis.ksu.edu (Anindya Banerjee) writes:

|> Is there any simple way to specify a generator of names (gensym in
|> Le_Lisp) in Typol?  I am writing a beta-reducer for the
|> lambda-calculus using substitutions and this requires renaming with
|> fresh names.

There is at least two solutions.

1- using the Le_Lisp function gensym:

In lisp define the following function:

(de genstring ()
	(catenate (gensym)))

and in Typol

import getsym(string, integer) from prolog;
import lispcall(integer, integer, integer, string) from prolog;

getsym("genstring", G)  &  lispcall(3, 0, G, gen)  (in a provided for example)
will give you in the variable gen a new string, that you may use as a value
for an atomic operator: id gen

(you can encapsulate this if you want)

2- defining gensym in prolog

aux$genlast(0).
aux$gensym(X) :- 
	retract(aux$genlast(N)),
	plus(N, 1, N1),
	concat('foo', N1, X),
	assert(aux$genlast(N1)).

and in Typol

import gensym(string) from aux;

gensym(X) will give you new strings.


The first solution will generate lisp symbols and prolog symbols,
the second only prolog symbols. As the hash table of prolog is not
that big, may be it is a good idea too use integers, and not strings

aux$gensym(X) :-
	retract(aux$genlast(N)),
	plus(N, 1, X),
	assert(aux$genlast(X)).
and in Typol
import gensym(integer) from aux;

gensym(X) will give you and integer to be used in an  'implemented as INTEGER'
as in  int X.

--
Send contributions to centaur@sophia.inria.fr. Registration and
administrative matters should be sent to centaur-request@sophia.inria.fr.
+----------------------------------------------------------------------------+
|     Thierry Despeyroux         | email: Thierry.Despeyroux@sophia.inria.fr |
|  I.N.R.I.A. Sophia-Antipolis	 | phone: +33 93 65 77 07		     |
|   2004, Route des Lucioles	 | fax:   +33 93 65 77 66		     |
|           B.P. 109		 | telex: INRIASA 970 050 F		     |
| F-06561 Valbonne Cedex, France |					     |
+----------------------------------------------------------------------------+