Nested function: Difference between revisions
Add Cowgol
m (added whitespace.) |
Not a robot (talk | contribs) (Add Cowgol) |
||
Line 339:
''PS: A function named make-list is already defined in Common Lisp, see [http://www.lispworks.com/documentation/HyperSpec/Body/f_mk_lis.htm#make-list specification].''
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
include "strings.coh";
sub MakeList(sep: [uint8], buf: [uint8]): (out: [uint8]) is
out := buf; # return begin of buffer for ease of use
var counter: uint32 := 0;
# Add item to string
sub AddStr(str: [uint8]) is
var length := StrLen(str);
MemCopy(str, length, buf);
buf := buf + length;
end sub;
sub MakeItem(item: [uint8]) is
counter := counter + 1;
buf := UIToA(counter, 10, buf);
AddStr(sep);
AddStr(item);
AddStr("\n");
end sub;
MakeItem("first");
MakeItem("second");
MakeItem("third");
[buf] := 0; # terminate string
end sub;
var buffer: uint8[100];
print(MakeList(". ", &buffer as [uint8]));</lang>
{{out}}
<pre>1. first
2. second
3. third</pre>
=={{header|D}}==
|