From: dc on
Hi,
Does anyone know of a reasonable version of a CL lib that will create
(relatively) standard pascal code?
I've looked briefly on google, but not found much.
Any links appreciated.
Thanks
DC
From: fortunatus on
Generate Pascal code from what? Can you show data structure and/or
library usage you have in mind?
From: Tamas K Papp on
On Mon, 15 Mar 2010 23:17:26 -0700, dc wrote:

> Hi,
> Does anyone know of a reasonable version of a CL lib that will create
> (relatively) standard pascal code?
> I've looked briefly on google, but not found much. Any links
> appreciated.

It is easy to write one. For example, this fits the specification
you have given us perfectly:

(defun generate-pascal-code ()
"Program HelloWorld(output);
begin
Writeln('Hello, world!')
end.")

Of course, it could happen that you need something more specific, but
you are unlikely to get help with that unless you explain what you
need.

Tamas
From: dc on
On Mar 17, 12:43 am, Tamas K Papp <tkp...(a)gmail.com> wrote:
> On Mon, 15 Mar 2010 23:17:26 -0700, dc wrote:
> > Hi,
> > Does anyone know of a reasonable version of a CL lib that will create
> > (relatively) standard pascal code?
> > I've looked briefly on google, but not found much. Any links
> > appreciated.
>
> It is easy to write one.  For example, this fits the specification
> you have given us perfectly:
>
> (defun generate-pascal-code ()
>   "Program HelloWorld(output);
> begin
>   Writeln('Hello, world!')
> end.")
>
> Of course, it could happen that you need something more specific, but
> you are unlikely to get help with that unless you explain what you
> need.
>
> Tamas

Ah, yes. I was far too vague. I wrote this as I was walking out the
door from work.
If I had simply added 'from existing CL code' to my above post, it
might have made a little more sense.

I'm hoping there's something like Parenscript for Pascal. My hope is
to be able to write and test routines in CL and (so long as I'm not
relying on too many CL features) create Pascal code from CL code.

My motivation for doing this is that in the code I'm dealing with
there are numerous boilerplate code sections that need to be written
for the architecture I'm using (not my choice) and I wondered how
useful it would be to generate some of it from CL, rather than type it
in myself.

So, if I had something like

(defun add(x y)
(+ x y))

If I wrapped the above defun around something like a pascal-code
macro, I could generate something like

function add(x, y: real) : real;
begin
Result := x + y;
end;

This example shows one of the problems, pascal needing to know about
types. There is something similar to this in parenscript, but it is a
little easier since types don't need to be explicitly stated in
javascript. I guess it's possible to work out the type of course (I
asked for a type inferencer once here and got a simple one from Pascal
Costanza I think), since CL compilers do this all the time.

The above add example is quite contrived, but having something that
would write code for me might be pretty handy.

I think 'Lisp in small pieces' basically takes Lisp and makes C code?
If this is possible, perhaps there is something like a lisp->Pascal
compiler out there already.

Does that explain it a little better?

Cheers
DC
From: Tamas K Papp on
On Tue, 16 Mar 2010 08:17:46 -0700, dc wrote:

> On Mar 17, 12:43 am, Tamas K Papp <tkp...(a)gmail.com> wrote:
>> On Mon, 15 Mar 2010 23:17:26 -0700, dc wrote:
>> > Hi,
>> > Does anyone know of a reasonable version of a CL lib that will create
>> > (relatively) standard pascal code?
>> > I've looked briefly on google, but not found much. Any links
>> > appreciated.
>>
>> It is easy to write one.  For example, this fits the specification you
>> have given us perfectly:
>>
>> (defun generate-pascal-code ()
>>   "Program HelloWorld(output);
>> begin
>>   Writeln('Hello, world!')
>> end.")
>>
>> Of course, it could happen that you need something more specific, but
>> you are unlikely to get help with that unless you explain what you
>> need.
>>
>> Tamas
>
> Ah, yes. I was far too vague. I wrote this as I was walking out the door
> from work.
> If I had simply added 'from existing CL code' to my above post, it might
> have made a little more sense.
>
> I'm hoping there's something like Parenscript for Pascal. My hope is to
> be able to write and test routines in CL and (so long as I'm not relying
> on too many CL features) create Pascal code from CL code.
>
> My motivation for doing this is that in the code I'm dealing with there
> are numerous boilerplate code sections that need to be written for the
> architecture I'm using (not my choice) and I wondered how useful it
> would be to generate some of it from CL, rather than type it in myself.
>
> So, if I had something like
>
> (defun add(x y)
> (+ x y))
>
> If I wrapped the above defun around something like a pascal-code macro,
> I could generate something like
>
> function add(x, y: real) : real;
> begin
> Result := x + y;
> end;
>
> This example shows one of the problems, pascal needing to know about
> types. There is something similar to this in parenscript, but it is a
> little easier since types don't need to be explicitly stated in
> javascript. I guess it's possible to work out the type of course (I
> asked for a type inferencer once here and got a simple one from Pascal
> Costanza I think), since CL compilers do this all the time.
>
> The above add example is quite contrived, but having something that
> would write code for me might be pretty handy.
>
> I think 'Lisp in small pieces' basically takes Lisp and makes C code? If
> this is possible, perhaps there is something like a lisp->Pascal
> compiler out there already.
>
> Does that explain it a little better?

Yes. It seems that you want to generate Pascal code from
S-expressions.

I don't think that there are existing libraries for this, since the
intersection of Pascal and Lisp programmers should be very, very
small. I don't know Pascal well enough to say if writing something
similar to ParenScript is possible, but types alone should not prevent
you from doing this.

Type inference is not going to help you much: eg your add function
works with numbers in Lisp, but AFAIK there is no corresponding
general numeric type in Pascal. So I would just use type
_annotation_. One possible syntax would be

(defun (add real) ((x real) (y real))
(+ x y))

but this interferes with constructs like (bind (((a b c) list)) ...).
You could use

(defun add/real (x/real y/real)
(+ x y))

and decompose the symbol names in your translator macro. A thin
syntactic layer like this should be easy to write. But I don't really
see what you gain by it: it would be Pascal with a nicer syntax that
saves a bit of typing, OTOH it is unlikely to integrate well into
whatever IDE you are using.

Tamas