help-3dldf
[Top][All Lists]
Advanced

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

[help-3dldf] Macros in 3DLDF


From: Laurence Finston
Subject: [help-3dldf] Macros in 3DLDF
Date: Wed, 22 Dec 2004 18:43:23 +0100 (MET)

Hello Nobre, et al,

I have now implemented a simple form of macro.
It's not as clever as true Metafont-style macros, but I hope
that you will find it usable.

I call them "defuns", a term borrowed from LISP (i.e.,
"define function").  The following contains two examples
of how to use them.  I've taken it from `sample0.ldf', which
I'm about to upload to Savannah.

defuns can optionally have arguments, which are specified
between parentheses, both in the declaration and the call.
They must all be variables, but the types are not specified
in the declaration.

defuns can be nested, as in the examples below.

I will probably add some error handling, but I need to take
a break now.

I think it should be possible to have any valid 3DLDF code in a defun, but
I haven't tested things that might cause problems, such as loops and
conditionals, yet.

If anyone has any questions, he/she should feel free to ask.

Laurence

************************************************************

beginfig(1);

defun a (b, c, d, e) =
b := "abc";
c := false;
d := unit_square;
e := (1, 2, 3);

defun f (g, h, i) =
g := "ggg";
h := true;
i := unit_square scaled (4, 5, 6);

message "g:";
show g;

message "h";
show h;

message "i:";
show i;

enddef;

message "b:";
show b;

message "c:";
show c;

message "d:";
show d;

message "e:";
show e;

f (b, c, d);

enddef;


string A;
bool B;
rectangle C;
point D;


a (A, B, C, D);

defun j =
message "This is `j'.";
defun k =
message "This is `k'.";
enddef;
k;
enddef;

j;

endfig;
end;


******************************************************

This is the output:

A:
>> abc
B:
>> false
C:
>> rectangle:
points.size() == 4
connectors.size() == 0
Using "--" as connector.
(-0.500000, 0.000000, -0.500000) -- (0.500000, 0.000000, -0.500000) --
(0.500000, 0.000000, 0.500000) -- (-0.500000, 0.000000, 0.500000) -- cycle;
fill_draw_value == 0
draw_color == 0
fill_color == 0
pen == 0
dash_pattern == 0
`arrow' == `Path::NO_ARROW'.
D:
>> (1.000000, 2.000000, 3.000000)
A:
>> ggg
B
>> true
C:
>> rectangle:
points.size() == 4
connectors.size() == 0
Using "--" as connector.
(-2.000000, 0.000000, -3.000000) -- (2.000000, 0.000000, -3.000000) --
(2.000000, 0.000000, 3.000000) -- (-2.000000, 0.000000, 3.000000) -- cycle;
fill_draw_value == 0
draw_color == 0
fill_color == 0
pen == 0
dash_pattern == 0
`arrow' == `Path::NO_ARROW'.
This is `j'.
This is `k'.
Exiting 3DLDF Version 1.2.0.0.









reply via email to

[Prev in Thread] Current Thread [Next in Thread]