Please visit https://cangjie-lang.cn/en/download and download the STS version of Cangjie.
Extract the tarball then, in the terminal in the extrated directory,
type source ${PATH_TO_EXTRACTED_DIR}/envsetup.sh.
You should now be good to go. simply type cjc <filename> to invoke
the compiler.
in addition to the above, the Windows package will have envsetup.bat
and envsetup.ps1 scripts that achieve the same as envsetup.sh.
One you're set up, verify everything by compiling your first Cangjie program.
Using your text editor of choice, saving the following program:
main() {
println("Hello, world!")
}
Invoke cjc hello.cj, then run ./main
If everything is setup correctly, then you should see "Hello, world!" printed out to your terminal.
For the remaineder of these exercises, your working directory should be the root directory of this repository.
Have a look at the code in the exercise02 directory.
You can compile the entire package with cjc -p exercise02 -o ex2, then run
as before with ./ex2
- Compile the package
- Finish the definitions of the
CircleareaandtoStringmethods. - Define a new class
Squarethat is a subclass ofRectangle
Take a look at expr.cj in the exercise03 directory. We have a
simple expression language represented with an algebraic data type
(ADT) and an evaluator function eval.
- Complete the defintion of
evalso that it evaluates the expression language with reasonable semantics. - Add some new expression types to the enum, and update
evalto support them. How about one with a different number of arguments?
There is an implemented version of expr.cj in the exercise04
directory. Look at main() for an example of how to use spawn in
Cangjie.
- Parallelise
evalusingspawnandFuture.get()
exercise05/expr.cj
contains the toy expression language again, but now with a call to
macro that allows you to create Expressions with infix syntax.
exercise05_macro contains a macro package, with the macro
definition and a recursive helper function.
To compile the macro package:
cjc --compile-macro -p exercise05_macro
To compile exercise 5:
cjc -p exercise05 -o ex5
- compile the macro package and exercise 5 and run it
- Extend the
transformfunction inmacros.cjto support the otherExpressiontypes.
We'll do it live!