Skip to content

dasylang/dasy

 
 

Repository files navigation

Dasy

The Dasypeltis, gansi, is considered an egg-eating snake. Their diet consists of all forms of eggs considering they have no teeth in which to eat living prey with.

Dasy is an experimental smart contract programming language in the lisp family. It is implemented by compiling to Vyper and benefits from the extensive optimizations and excellent performance of Vyper.

Learn more in the documentation

Examples

More examples at Dasy By Example

(defvars :public
        myMap (hash-map :address :uint256)
        nums (dyn-arr :uint256 3)
        owner :address)

(defn __init__ [] :external
  (set self/owner msg/sender)
  (set-at self/myMap msg/sender 10)
  (do ;; wrap statements in do
    (.append self/nums 11)))

(defn getOwnerNum [] :uint256 :external
  (get-at self/myMap self/owner))

Installation

For use as a library

pip install git+https://github.com/dasylang/dasy.git

For use as an executable via pipx

pipx install git+https://github.com/dasylang/dasy.git
pip install ape-dasy

Motivation

Macros

There are a lot of opportunities for macros in smart contracts. They can also be used to prototype features before implementing them at a lower level in the vyper compiler.

macros are written in Hy, a pythonic lisp. They allow us to transform our code at compile time, allowing the developer to tailor the language itself to their needs.

cond and condp are examples of useful macros that help make your code shorter, yet easier to understand.

(defn useIf [:uint256 x] :uint256 :external
  (if (<= x 10)
      (return 1)
      (if (<= x 20)
          (return 2)
          (return 3))))

;; cond macro helps prevent deeply nested ifs
(defn useCond [:uint256 x] :uint256 :external
  (cond
    (<= x 10) (return 1)
    (<= x 20) (return 2)
    :else     (return 3)))

;; condp saves you from repeating the same operation
(defn useCondp [:uint256 x] :uint256 :external
  (condp <= x
    10 (return 1)
    20 (return 2)
    :else (return 3)))

For fun

About

a lisp built on top of vyper

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 85.0%
  • Hy 15.0%