Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of real/typed format strings #67

Merged
merged 10 commits into from
Oct 27, 2022
Merged

Allow the use of real/typed format strings #67

merged 10 commits into from
Oct 27, 2022

Conversation

skx
Copy link
Owner

@skx skx commented Oct 27, 2022

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:

  • %s -> string
  • %d -> decimal
  • %f -> float
  • %t -> boolean
  • %c -> character

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

skx added 7 commits October 27, 2022 20:34
This allows the user to use a real/typed format string to print
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:

* %s -> string
* %d -> decimal
* %f -> float
* %t -> boolean
* %c -> character

This is achieved via the use of an (optional) interface, instead
of blindly casting things to a string.
Also simplified the argument-handling for sprintf/print
@skx
Copy link
Owner Author

skx commented Oct 27, 2022

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.

@skx skx merged commit 78bdd79 into master Oct 27, 2022
@skx skx deleted the 66-formatting branch October 27, 2022 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Our printf/sprintf functions are wrong.
1 participant