newLISP Fan Club

Forum => newLISP in the real world => Topic started by: Bat on November 06, 2003, 01:27:38 PM

Title: Optional args, and line length for printing.
Post by: Bat on November 06, 2003, 01:27:38 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.
Title:
Post by: Lutz on November 06, 2003, 04:57:05 PM
>>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
Title:
Post by: Bat on November 08, 2003, 06:51:38 AM
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.
Title:
Post by: Lutz on November 09, 2003, 06:52:22 AM
I will do something user-configurable in the next version.



Lutz
Title:
Post by: Lutz on November 09, 2003, 01:52:19 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
Title:
Post by: Bat on November 09, 2003, 06:22:51 PM
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)))
Title:
Post by: Lutz on November 10, 2003, 05:03:48 AM
remember I am in a timezone 6 hours behind yours, that makes 24 + 6 = 30 ;-)



Lutz