-
Notifications
You must be signed in to change notification settings - Fork 4
Snippets
We have already met snippets, without noticing it, in the page SQL interop. Consider the following command.
add (name string, age int) :
put SQL ---
INSERT INTO People
VALUES |name, age|
The --- operator is in fact a special kind of constructor. It forms a struct of type SQL with two fields, text of type string and data of type list. The text field contains the raw text after the ---, so in this case INSERT INTO People ... etc. And data contains a list containing alternately the plain strings in the raw text and the values the expressions within bars evaluate to.
To create a snippet type, declare it under the newtypes headword.
newtype
Cpp = snippet
Python = snippet
Prolog = snippet
Of course that still leaves you with the difficulty of implementing the language! The snippet syntax is just a nice way of wrapping up and presenting you with the data you need to do that. In the case of SQL, Pipefish has functions in the (automatically imported) world library which mean that put(x SQL), post(x SQL) and `delete(x SQL) are defined for you and know about the configuration of your SQL server.
There is also a ready-to-use HTML snippet. The post command is defined for it such that it will simply turn the data into a single string of text, using the built-in (and possibly overloaded) string function to turn the individual elements of the data list into text and concatenating them together.
🧿 Pipefish is distributed under the MIT license. Please steal my code and ideas.
- Getting started
- Language basics
- The type system and built-in functions
- Functional Pipefish
- Encapsulation
- Imperative Pipefish
-
Imports and libraries
- The crypto/aes library
- The crypto/bcrypt library
- The crypto/rand library
- The crypto/rsa library
- The crypto/sha_256 library
- The crypto/sha_512 library
- The database/sql library
- The encoding/base_32 library
- The encoding/base_64 library
- The encoding/csv library
- The encoding/json library
- The files library
- The fmt library
- The html library
- The image library
- The image/bmp library
- The image/color library
- The image/jpeg library
- The image/png library
- The lists library
- The markdown library
- The math library
- The math/big library
- The math/cmplx library
- The math/rand library
- The net/http library
- The net/mail library
- The net/smtp library
- The net/url library
- The os/exec library
- The path library
- The path/filepath library
- The reflect library
- The regexp library
- The strconv library
- The strings library
- The terminal library
- The time library
- The unicode library
- Advanced Pipefish
- Developing in Pipefish
- Deployment
- Appendices