M content/language/chapters/1-5_symbols-keywords.html => content/language/chapters/1-5_symbols-keywords.html +35 -6
@@ 1,24 1,53 @@
+++
title: "1.5 - Symbols / Keywords"
-date: "2022-08-31"
+date: "2022-09-07"
+++
<h1>Symbols / Keywords</h1>
+<p>Like most Lisp's Nujel supports symbols as well as keywords. In general they are very similar to Scheme, so much that some SRFI's have been implemented as is.</p>
-<p>Keywords have to start, or end, with a single <code>:</code> character and are self-evaluating. They are a distinct type from symbols but can be easily converted.</p>
+<box-wrap box-color="red">
+ <h3>Warning</h3>
+ <p>It is adviced not to use periods (<code>.</code>) as well as forward and backward slashes (<code>/</code>, <code>\</code>) in symbols interned by the reader directly, this is because these characters will very likely become used in reader macros in the future.</p>
+</box-wrap>
-<p>Regarding their usage, keywords should be used when the keyword itself is the value to be used, symbols should be used to give a label to another value.</p>
+<h3>1. Symbols</h3>
+<p>Symbols in Nujel behave pretty much the same as in most other Lisps, in that they are implictly looked up unless quoted.</p>
+<pre class="source source-nujel">
+asd ; Every symbol is implicitly looked up, with an exception thrown on failure
+; => :unbound-variable
+
+'asd ; By quoting a symbol this implicit look up can be disabled
+; => asd
+
+[string->symbol "asd"] ; You can also turn any old string into a symbol, this is sometimes called interning a string
+; => asd
+
+[== 'asd [string->symbol "asd"]] ; The two values actually point to the same underlying data structure
+; => #t
+</pre>
+<box-wrap box-color="yellow">
+ <h3>Implementation detail</h3>
+ <p>Currently symbols are truncated after 63 characters, this limit hasn't been much of a problem yet but it will be addressed when it becomes necessary.</p>
+</box-wrap>
+
+<h3>2. Keywords</h3>
+<p>Since quoting can become quite tedious there is another very similar data type, keywords. They share most functionality with symbols with the main difference being that they will not be implicitly looked up.</p>
+<p>By pre- or suffixing a symbol with a <code>:</code> the reader will return a keywords.</p>
<pre class="source source-nujel">
:asd ; A keyword
; => :asd
-
+
asd: ; Another keyword
; => asd:
-
+
[= asd: :asd] ; It doesn't matter where we put the colon
; => #t
-
+
[= :asd [symbol->keyword 'asd]]
; => #t
</pre>
+
+<h3>3. Usage</h3>
+<p>Regarding their usage, keywords should be used when the keyword itself has a useful meaning, symbols should be used to label other values which could work just as well with another symbol associated.</p>
M ssg/theme/default.nuj => ssg/theme/default.nuj +3 -2
@@ 1,9 1,10 @@
[import [parse :as theme/parse] "../theme"]
[def +theme-path+ [fmt "{}/default" *module-path*]]
-[def base-template [theme/parse +theme-path+ [slurp [fmt "{+theme-path+}/base.html"]]]]
+[def main-template [theme/parse +theme-path+ [slurp [fmt "{+theme-path+}/templates/main.html"]]]]
[defn render [ctx path]
"Apply the default theme to a particular path"
:export
- [base-template ctx path]]
+ [main-template ctx path]]
+
R ssg/theme/default/base.html => ssg/theme/default/templates/main.html +0 -0