From 4482154d4ab844401b8c899a0ba083585eb87234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sved=C3=A4ng?= Date: Sun, 28 Jan 2018 06:35:08 +0100 Subject: [PATCH] Updated help chapters in the repl. --- examples/bugs.carp | 38 +++++++++++++++++++------------------- src/Commands.hs | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/examples/bugs.carp b/examples/bugs.carp index 4d0b89d4..b50587de 100644 --- a/examples/bugs.carp +++ b/examples/bugs.carp @@ -31,26 +31,26 @@ ;; BUG F ;; Generic Hashmap Stuff -;; (use Array) +(use Array) -;; (deftype (Entry a b) [key a value b]) -;; (deftype (Bucket a b) [entries (Array (Entry a b))]) +(deftype (Entry a b) [key a value b]) +(deftype (Bucket a b) [entries (Array (Entry a b))]) -;; (defmodule String -;; (defn zero [] @"")) +(defmodule String + (defn zero [] @"")) -;; (defn get-object [bucket lookup-key] -;; (let-do [pairs (Bucket.entries bucket) -;; result (zero)] -;; (for [i 0 (count pairs)] -;; (let [pair (nth pairs i)] -;; (when (= (Entry.key pair) &lookup-key) -;; (set! &result @(Entry.value pair))))) -;; result)) +(defn get-object [bucket lookup-key] + (let-do [pairs (Bucket.entries bucket) + result (zero)] + (for [i 0 (count pairs)] + (let [pair (nth pairs i)] + (when (= (Entry.key pair) &lookup-key) + (set! &result @(Entry.value pair))))) + result)) -;; (defn main [] -;; (let-do [start (Bucket.init [(Entry.init @"hello" 12345) -;; (Entry.init @"goodbye" 666)])] -;; (IO.println &(str &start)) -;; (IO.println &(str @(get-object &start @"hello"))) -;; )) +(defn main [] + (let-do [start (Bucket.init [(Entry.init @"hello" 12345) + (Entry.init @"goodbye" 666)])] + (IO.println &(str &start)) + (IO.println &(str @(get-object &start @"hello"))) + )) diff --git a/src/Commands.hs b/src/Commands.hs index f2e9c8d5..4ff4a249 100644 --- a/src/Commands.hs +++ b/src/Commands.hs @@ -244,7 +244,13 @@ commandHelp [XObj (Str "macros") _ _] = return dynamicNil commandHelp [XObj (Str "structs") _ _] = - liftIO $ do putStrLn "A type definition will generate the following methods:" + liftIO $ do putStrLn "To define a struct without any generic member variables:" + putStrLn "(deftype [ , ...])" + putStrLn "" + putStrLn "If you need generic members:" + putStrLn "(deftype ( ...) [ , ...])" + putStrLn "" + putStrLn "A type definition will generate the following methods:" putStrLn "Getters ( (Ref ))" putStrLn "Setters (set- )" putStrLn "Updaters (update- )" @@ -270,6 +276,17 @@ commandHelp [XObj(Str "shortcuts") _ _] = putStrLn "" return dynamicNil +commandHelp [XObj(Str "interop") _ _] = + liftIO $ do putStrLn "(register ) - Make an external variable or function available for usage." + putStrLn "(register-type [ , ...]) - Make an external struct available for usage." + putStrLn "" + putStrLn "C-compiler configuration:" + putStrLn "(system-include ) - Include a system header file." + putStrLn "(local-include ) - Include a local header file." + putStrLn "(add-cflag ) - Add a cflag to the compilation step." + putStrLn "(add-lib ) - Add a library flag to the compilation step." + return dynamicNil + commandHelp [] = liftIO $ do putStrLn "Compiler commands:" putStrLn "(load ) - Load a .carp file, evaluate its content, and add it to the project." @@ -282,26 +299,22 @@ commandHelp [] = putStrLn "(info ) - Get information about a binding." putStrLn "(project) - Display information about your project." putStrLn "(quit) - Terminate this Carp REPL." - putStrLn "(help ) - Available chapters: \"language\", \"macros\", \"structs\", \"shortcuts\", \"about\"." + putStrLn "(help ) - Available chapters: \"language\", \"macros\", \"structs\", \"interop\", \"shortcuts\", \"about\"." + putStrLn "" + putStrLn "(project-set! ) - Change a project setting (not fully implemented)." putStrLn "" putStrLn "To define things:" - putStrLn "(def ) - Define a global variable." - putStrLn "(defn [] ) - Define a function." - putStrLn "(module ...) - Define a module and/or add definitions to an existing one." - putStrLn "(deftype ...) - Define a new type." - putStrLn "(register ) - Make an external variable or function available for usage." - putStrLn "(defalias ) - Create another name for a type." - putStrLn "" - putStrLn "C-compiler configuration:" - putStrLn "(system-include ) - Include a system header file." - putStrLn "(local-include ) - Include a local header file." - putStrLn "(add-cflag ) - Add a cflag to the compilation step." - putStrLn "(add-lib ) - Add a library flag to the compilation step." - putStrLn "(project-set! ) - Change a project setting (not fully implemented)." + putStrLn "(def ) - Define a global variable." + putStrLn "(defn [] ) - Define a function." + putStrLn "(definterface ) - Create an interface for a group of functions sharing the same name." + putStrLn "(defmodule ...) - Define a module and/or add definitions to an existing one." + putStrLn "(deftype [ , ...]) - Define a new struct type." putStrLn "" putStrLn "Compiler flags:" putStrLn "-b - Build." putStrLn "-x - Build and run." + putStrLn "--no-core - Don't load the core library." + putStrLn "--log-memory - Enables use of memory logging functions in the Debug module." return dynamicNil commandHelp args =