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

Added (version) primitive to REPL #124

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .yalrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
;;
;; OK now we're done, show a banner and launch the REPL
;;
(print "YAL version %s" (version))
(print "This is ~/.yalrc on %s - %s %s" (trim (hostname)) (os) (arch) )
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var (
LISP *eval.Eval
)

// versionFn is the implementation of the (version) primitive.
func versionFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
return primitive.String(version)
}

// create handles the setup of our global interpreter and environment.
//
// The standard-library will be loaded, and os.args will be populated.
Expand All @@ -50,6 +55,13 @@ func create() {
// Populate the default primitives
builtins.PopulateEnvironment(ENV)

// Add the (version) function
ENV.Set("version",
&primitive.Procedure{
F: versionFn,
Help: "Return the version of the interpreter.\n\nSee-also: arch, os",
Args: []primitive.Symbol{}})

// Build up a list of the command-line arguments
args := primitive.List{}

Expand Down Expand Up @@ -264,7 +276,6 @@ func main() {
//
// No arguments mean this is our REPL
//
fmt.Printf("YAL version %s\n", version)
reader := bufio.NewReader(os.Stdin)

//
Expand Down