skx / yal

Yet another lisp interpreter
GNU General Public License v2.0
16 stars 0 forks source link

Allow the use of real/typed format strings #67

Closed skx closed 1 year ago

skx commented 1 year ago

Once complete this pull-request will close #66, by allowing ("forcing") the use of real/typed format strings.

Currently we allow the user to use a real/typed format string to the print primitive, for example:

$ ./yal -e '(print "%s:%d:% .4f %s %t %c" "steve" 3 (/ 1 3) (list 1 2 3 4) false #\#)'
steve:3: 0.3333 (1 2 3 4) false #

Here we see the following format-strings:

This is achieved via the use of an (optional) interface, instead of blindly casting things to a string.

skx commented 1 year ago

Looks good new, but I need to update our examples:

yal test.lisp
..
..
foo is now set to %!s(int=3)
foo is unset now, outside the scope of the `let`
Sum of 1-100: %!s(int=5050)
%!s(int=1)  squared is %!s(int=1)
%!s(int=2)  squared is %!s(int=4)
%!s(int=3)  squared is %!s(int=9)
%!s(int=4)  squared is %!s(int=16)
%!s(int=5)  squared is %!s(int=25)
%!s(int=6)  squared is %!s(int=36)
%!s(int=7)  squared is %!s(int=49)
%!s(int=8)  squared is %!s(int=64)
%!s(int=9)  squared is %!s(int=81)
%!s(int=10) squared is %!s(int=100)
%!s(int=-2) is negative
%!s(int=-2) is EVEN
%!s(int=-1) is negative
%!s(int=-1) is ODD
%!s(int=0) is ZERO
%!s(int=0) is EVEN
%!s(int=1) is ODD

All the sample code, and standard-library, needs to be updated/tested to make sure it makes sense.