Optional args, and line length for printing.

Q&A's, tips, howto's

Optional args, and line length for printing.

Postby Bat » Thu Nov 06, 2003 9:27 pm

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.
Bat
 
Posts: 10
Joined: Fri Oct 10, 2003 3:38 pm

Postby Lutz » Fri Nov 07, 2003 12:57 am

>>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
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby Bat » Sat Nov 08, 2003 2:51 pm

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.
Bat
 
Posts: 10
Joined: Fri Oct 10, 2003 3:38 pm

Postby Lutz » Sun Nov 09, 2003 2:52 pm

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

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

Postby Lutz » Sun Nov 09, 2003 9:52 pm

>>>>>>
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
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Postby Bat » Mon Nov 10, 2003 2:22 am

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)))
Bat
 
Posts: 10
Joined: Fri Oct 10, 2003 3:38 pm

Postby Lutz » Mon Nov 10, 2003 1:03 pm

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

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


Return to newLISP in the real world

Who is online

Users browsing this forum: joejoe and 1 guest