h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
311 stars 23 forks source link

Polymorphic `chr` works for int => string but not for string => int #60

Closed agentofuser closed 4 years ago

agentofuser commented 4 years ago

When an int is on the stack, chr replaces it with the appropriate single-ascii-char string (if it's a printable character; empty otherwise), as expected.

When a single-char ASCII string is on the stack, chr (which from the docs I'm assuming is polymorphic) gives an error, instead of leaving the corresponding int value for the character on the stack.

λ "h" chr
(!) <repl>(1,7) [chr]: Symbol: chr - Incorrect values found on the stack:
- expected: int chr
- got:      string chr
    <repl>(1,7) in symbol: chr

The new getchr and putchr from #59 work perfectly btw, thank you :))

h3rald commented 4 years ago

Ooops... no, chr isn't polymorphic... to get the ASCII code of a character you have to use ord (I basically exposed Nim's chr and ord methods)... that was a typo in the docs 😜 -- fixed now.