-
Notifications
You must be signed in to change notification settings - Fork 4
Snippets
We have already met snippets, without noticing it, in the pages on SQL interop and microservices. 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 and env. The text field contains the text after the ---, so in this case INSERT INTO People ... etc. And env contains a map in which the keys are the names of all the variables in scope (represented as strings) and the values are the values of the variables.
In order for this to work, SQL had to be declared as a language under the languages headword (this is done in the world.pf library, which is automatically imported). You can do this too, let your imagination run wild!
languages
Cpp
Python
Prolog
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 both the SQL and microservice snippets, I have used the | symbol to delimit bits of Pipefish which should be interpreted by the calling context. However, | has no semantic or syntactic significance and was chosen because it means nothing in Pipefish and so is a spare symbol. It is therefore a useful convention but not a necessity.
🧿 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