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

Support character literals #64

Closed
skx opened this issue Oct 26, 2022 · 0 comments · Fixed by #65
Closed

Support character literals #64

skx opened this issue Oct 26, 2022 · 0 comments · Fixed by #65
Assignees

Comments

@skx
Copy link
Owner

skx commented Oct 26, 2022

Something like this is sufficient as a proof of concept:

git diff eval/eval.go 
diff --git a/eval/eval.go b/eval/eval.go
index 1cae1b0..694b05d 100644
--- a/eval/eval.go
+++ b/eval/eval.go
@@ -98,10 +98,17 @@ func (ev *Eval) atom(token string) primitive.Primitive {
        case "nil":
                return primitive.Nil{}
        }
+
+       // string
        if token[0] == '"' {
                return primitive.String(strings.ReplaceAll(strings.Trim(token, `"`), `\"`, `"`))
        }
 
+       // character literal
+       if strings.HasPrefix(token,"#\\") {
+               return primitive.String( token[2:] )
+       }
+
        // if it isn't a number then it is a symbol
        f, err := strconv.ParseFloat(token, 64)
        if err == nil {

Once that is done we should obviously have "primitive.Char(acter)", and implement some character primitives:

  • char=
  • char/=
  • char<
  • char>
  • char<=
  • char>=

And probably look at some kinda way to split a string into characters, and vice versa. (split) is used for that right now, but it officially returns strings - and I just split into characters via an empty second argument

@skx skx self-assigned this Oct 26, 2022
@skx skx mentioned this issue Oct 26, 2022
4 tasks
@skx skx closed this as completed in #65 Oct 27, 2022
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 a pull request may close this issue.

1 participant