Optional args, and line length for printing.

Q&A's, tips, howto's
Locked
Bat
Posts: 10
Joined: Fri Oct 10, 2003 3:38 pm

Optional args, and line length for printing.

Post by Bat »

Just two more quests (by now !):
1. Is it possible to use optional arguments in functions, other than through 'define-macro' ? I dont quite get it clear from the manual. It looks fine anyway, since a variable-number-of-args function is certainly a strange concept itself... not very 'mathematical' to say least.


2.Why is line length limited to 64 chars for print and println ? This limitation occurs also when printing to files, and looks odd.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

>>1. Is it possible to use optional arguments in functions, other than through 'define-macro' ?

Yes, in any user defined function, be it 'define' or 'define-macro' you can use optional arguments. All arguments not filled in by the caller, but specified in a function definition will be filled with 'nil'. So in a 'mathematical sense' it is really not a 'optional arguments' funtion, as all parameters defined in the function are well defined by this rule. It is more like a 'short cut', which permits you define parameters with 'nil' implicitely when not passing them explicitly.

>>2.Why is line length limited to 64 chars for print and println ? This limitation occurs also when printing to files, and looks odd.

This is just the 'pretty print' feature to make it fit onto most printed pages, terminal screens etc.. Its is also nice to have any output generated be human readable, even with data in files.

Sometimes I thought to make this user configurable, if this is important to you, let me know, it would be easy to add.


Lutz

Bat
Posts: 10
Joined: Fri Oct 10, 2003 3:38 pm

Post by Bat »

I personally prefer that no breaklines are introduced without my control. You see, if I print a datase to a file one register a line, then when I read the file with read-line, I'm sure I get a whole register, otherwise its awkward.

Maybe you're right that it should be left as an option to break lines when printing to files. Since print implements nicely this with "\n" "\r".

Another possible way is to leave print as it is, and wrk out a nice (pretty-print) function to allow for all this problems.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

I will do something user-configurable in the next version.

Lutz

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

>>>>>>
personally prefer that no breaklines are introduced without my control. You see, if I print a datase to a file one register a line, then when I read the file with read-line, I'm sure I get a whole register, otherwise its awkward.
>>>>>>

totally forgot about the following: you can supress pretty-printing by converting to a string first,
i.e.:

(string expression)

will return expression vonverted to a string but without any beautification. That should serve your purpose. I still will do some user-configuration for pretty-printing, changing line-length, indentation etc..

Lutz

Bat
Posts: 10
Joined: Fri Oct 10, 2003 3:38 pm

Post by Bat »

That does it, you're right
Where do you get your time from ? Are your days -as ours- 24-h long ?

(dotimes (x 1000) (print-pretty '(thanks again)))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

remember I am in a timezone 6 hours behind yours, that makes 24 + 6 = 30 ;-)

Lutz

Locked