or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
tags:
Alucard
An Introduction to Alucard
Installation
The easiest way to install Alucard at the moment is through ros.
ros install sbcl-bin
ros install asdf
git clone https://github.com/anoma/juvix-circuits.git
cd juvix-circuits
ros install "nobody-famous/alive-lsp"
make install
make all
will install it in./build/
as well.The last command will add it to
~/.local/bin/
, so make sure that is on your path!Now we can run alucard!
Terminal Commands
There are basically 2 ways to run alucard programs.
Interactive Mode
The interactive mode is via a REPL in Emacs/VSCode. To run the interactive mode,
If you are using a SLIME (VS-Code uses SLIME), replace the
-y
with-s
.Then use your client (e.g. Slime or Sly) to connect to localhost with port 4005 (or whatever port is shown in the terminal). You can set the port with the
-p
option.If you are using vscode it might spit you out in the cl-user package. to check your prompt should say
ALUSER>
in vs-code or emacs. If that is the case then run the followingone can quit out of the repl by typing
(quit)
.Batch Mode
Batch mode lets you provide input from files to the
alu.image
executable with the-i
flag and specify the output file with the-o
flag.If the
-o
flag is not given, you will go into interactive mode.To specify the function that will act as the entry point to one's circuit, you can write
(entry-point function-name)
in the file, otherwise no code will be generated.Running Alucard from Emacs
If you are running sly,
M-x sly-connect
to localhost with the port number shown in your terminal earlier.If one is using
ccl
instead ofSBCL
you might want to run:Running Alucard as a library
You can also
(ql:quickload :alu)
if one has theasd
file on the path or have loaded into one's environemnt, and have the same functionality!Running Alucard from VSCode
Please check the readme
Writing programs and generating VAMP-IR
You know you are ready to get going when typing
*package*
in your REPL returnsor your REPL prompt says
ALUSER>
.Let's define a simple circuit, which represents the equation, \(x+3 = 0\).
In the above code, the keyword
defcircuit
is used to denote that we are defining a polynomial circuit, namedadd-three
. The circuit takes as input the integerx
, which is apublic
input, and the output istrue
if the equation is satisfied, and false if not.For example, the VAMP-IR code for
add-three
is shown below.Note that since the compiler pipeline is currently incomplete, it is not yet possible to run VAMP-IR and generate output.
Currently it's good to run
vampir
on various circuits created, as the type checker currently only runs when trying to extract.Let's look at some more examples.
The follow circuit represents the equation \(x^3 + 3x^2 + 2x + 3y+ 4 =0\).
We can also define a circuit to calculate the square root of an input in the following manner.
The
def
plays a role similar tolet
in Rust. Thewith-constraint
macro can be used in any situation where we want a variable to be subject to certain constraints.Alucard also allows us to define custom datatypes.
Let us define the type
point
which defines a point on the Cartesian plane.Let's write a function to calculate the distance of this point from the origin. We'll make use of the
square-root
function we wrote earlier.Let us now mark this function as the entry point to the file
(entry-point distance)
We can also invoke the same functionality from the repl as well
Some of this formula is repetitive, namely the
(exp (lookup pt) 2)
we can use the common lisp integration to remove such repetitive looking code.
Namely we can use
flet
, which defines a local function to be our square function.If we find this function general enough we can move it to the top level with
defun
.A lot more can be abstracted, we have the entire toolkit of the common lisp programming language to help abstract away alucard code!
A lot more information on this can be found in the reference manual
Debugging
Let us say we try to make a type error.
In this code, we are saying the expected output of square should be of
(int 32)
, however the type should really just beint
. We can move thischeck
to any part of the expression in thesquare
function and the error would be the same.Here we get the type error message saying that
(int 32)
andint
are not compatable, and further the stack trace to the point.It is saying that the expression
(EXP CORD 2)
caused the error as we stated that the type must be of(int 32)
right before!The stack trace just give the expression dump until the current point where the error occurs.
Reporting Compiler Errors
If the system errors with a very baroque error message like
And spits you into a repl, please file an issue or message
mariari
directly. These are internal errors and they might show up!