]> gitweb.factorcode.org Git - factor.git/commitdiff
syntax: adding INITIALIZE:
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 26 Jan 2022 18:41:30 +0000 (10:41 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 26 Jan 2022 18:41:30 +0000 (10:41 -0800)
basis/bootstrap/syntax.factor
core/syntax/syntax-docs.factor
core/syntax/syntax.factor

index ba32f887ca890c3e771c8c0370fa949b98e91d56..5e62320f07a950c287eb7364d4cecda4674a5669 100644 (file)
@@ -44,6 +44,7 @@ IN: bootstrap.syntax
         "BUILTIN:"
         "SYMBOL:"
         "SYMBOLS:"
+        "INITIALIZE:"
         "CONSTANT:"
         "TUPLE:"
         "final"
index bbca72ea4ff1e81008a6da778ad5cf5fe046b9cf..f98a694cf12de930c48d3ad97fec7c8f4bdef10f 100644 (file)
@@ -503,6 +503,25 @@ HELP: SYMBOLS:
 { $description "Creates a new symbol for every token until the " { $snippet ";" } "." }
 { $examples { $example "USING: prettyprint ;" "IN: scratchpad" "SYMBOLS: foo bar baz ;\nfoo . bar . baz ." "foo\nbar\nbaz" } } ;
 
+HELP: INITIALIZE:
+{ $syntax "INITIALIZE: word ... ;"  }
+{ $description "If " { $snippet "word" } " does not have a value in the global namespace, calls the definition and assigns the result to " { $snippet "word" } " in the global namespace." }
+{ $examples
+    { $unchecked-example
+        "USING: math namespaces prettyprint ;"
+        "SYMBOL: foo"
+        "INITIALIZE: foo 15 sq ;"
+        "foo get-global ."
+        "225" }
+    { $unchecked-example
+        "USING: math namespaces prettyprint ;"
+        "SYMBOL: foo"
+        "1234 foo set-global"
+        "INITIALIZE: foo 15 sq ;"
+        "foo get-global ."
+        "1234" }
+} ;
+
 HELP: SINGLETON:
 { $syntax "SINGLETON: class" }
 { $values
index 7f48f5fc435fe0bb4f28f5071dd302e2e19a1329..99efa805a7510fdfd287604b24f1c1542dd3c224 100644 (file)
@@ -134,6 +134,10 @@ IN: bootstrap.syntax
         ";" [ create-word-in [ reset-generic ] [ define-symbol ] bi ] each-token
     ] define-core-syntax
 
+    "INITIALIZE:" [
+        scan-word parse-definition [ initialize ] 2curry append!
+    ] define-core-syntax
+
     "SINGLETONS:" [
         ";" [ create-class-in define-singleton-class ] each-token
     ] define-core-syntax