Coder Social home page Coder Social logo

mua-lang's Introduction

mua-lang

A simple lisp-like functional language's interpreter, mostly based on PPL(Principle of Programming Language) course assignment of ZJU.

一个简单的lisp-like函数式语言解释器,基于PPL的课程大作业。

实现的特性

  • 基本数据类型定义和运算
  • 逻辑运算和if语句分支
  • 列表操作
  • 闭包和高阶函数
  • 保存和加载命名空间(不含闭包)
  • 保存和加载闭包
  • 尾递归优化
  • 注释
  • 高精度数字

语法说明 Language Specification

详细的语法说明见mua-spec.md.

mua代码示例

最大公约数

一个简单的递归求解最大公约数的例子

make "gcd [[a b][
    if eq :b 0
        [return :a]
        [return gcd :b mod :a :b]
]]
print gcd 18 14
print gcd 18 13
print gcd 120 12

# output: 2 1 12

使用Z组合子求阶乘

使用Z组合子来求解阶乘,注意大量使用了闭包

make "fact_nicer [[rec][
    make "g [[x][
        if eq :x 0
            [return 1]
            [return mul :x rec sub :x 1]
    ]]
    return :g
]]

make "z_comb [[g][
    make "t [[r][
        make "y [[yy][
            make "tmp r :r
            return tmp :yy
        ]]
        return g :y
    ]]
    return t :t
]]

make "fact_z z_comb :fact_nicer
print fact_z 5

# ouput: 120

License

THIS PROJECT IS OPEN SOURCE UNDER MIT LICENSE, BUT WITH A LIMITATION:

ANYONE CANNOT USE ANY PART OF THIS PROJECT IN ANY COURSE OF ZJU AS COURSE ASSIGNMENT.

项目根据MIT协议开源,但有如下限制:

任何人不得在浙江大学的任何课程中使用本项目的任何部分作为课程作业。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.