MAL“标准库”

alias-hacks

aliases for common clojure names to mal builtins

  • let / when / def / fn / defn
  • partial

benchmark

  • benchmark
    An alternative approach, to complement perf

equality

This file checks whether the = function correctly implements equality of hash-maps and sequences (lists and vectors). If not, it redefines the = function with a pure mal (recursive) implementation that only relies on the native original = function for comparing scalars (integers, booleans, symbols, strings, keywords, atoms, nil).

  • scalar-equal?
    Save the original (native) = as scalar-equal?
  • mal-equal?
    This implements = in pure mal (using only scalar-equal? as native impl)

load-file-once

  • load-file-once
    Like load-file, but will never load the same path twice.

memoize

Memoize any function.

  • memoize
    Implement memoize using an atom (mem) which holds the memoized results (hash-map from the arguments to the result). When the function is called, the hash-map is checked to see if the result for the given argument was already calculated and stored. If this is the case, it is returned immediately; otherwise, it is calculated and stored in mem.
    For recursive functions, take care to store the wrapper under the same name than the original computation with an assignment like (def! f (memoize f)), so that intermediate results are memorized.

perf

Mesure performances.

  • time
    Evaluate an expression, but report the time spent
  • run-fn-for
    Count evaluations of a function during a given time frame.
      ;; fn       : function without parameters
      ;; max-secs : number (seconds)
      ;; return   : number (iterations)
    

pprint

  • pprint
    Pretty printer a MAL object.

protocols

A sketch of Clojure-like protocols, implemented in Mal.

  • find-type
    This function maps a MAL value to a keyword representing its type.
    Most applications will override the default with an explicit value for the :type key in the metadata.
  • defprotocol
    A protocol (abstract class, interface…) is represented by a symbol.
    It describes methods (abstract functions, contracts, signals…).
    Each method is described by a sequence of two elements.
    First, a symbol setting the name of the method.
    Second, a vector setting its formal parameters.
    The first parameter is required, plays a special role.
    It is usually named this (self…).
    For example,
       (defprotocol protocol
         (method1 [this])
         (method2 [this argument]))
    ;; can be thought as:
       (def! method1 (fn* [this]) ..)
       (def! method2 (fn* [this argument]) ..)
       (def! protocol ..)
    ;; The return value is the new protocol.
    
    A protocol is an atom mapping a type extending the protocol to another map from method names as keywords to implementations.
  • extend
    A type (concrete class…) extends (is a subclass of, implements…) a protocol when it provides implementations for the required methods.
       (extend type protocol {
         :method1 (fn* [this] ..)
         :method2 (fn* [this arg1 arg2])})
    
    Additional protocol/methods pairs are equivalent to successive calls with the same type.
    The return value is nil.
  • satisfies?
    An object satisfies a protocol when its type extends the protocol, that is if the required methods can be applied to the object.
    If (satisfies protocol obj) with the protocol below then (method1 obj) and (method2 obj 1 2) dispatch to the concrete implementation provided by the exact type.
    Should the type evolve, the calling code needs not change.

reducers

Left and right folds.

  • reduce
    Left fold (f (… (f (f init x1) x2) …) xn)
  • foldr
    Right fold (f x1 (f x2 (… (f xn init)) …))
    The natural implementation for foldr is not tail-recursive, and the one based on reduce constructs many intermediate functions, so we rely on efficient nth and count.

test_cascade

Iteration on evaluations interpreted as boolean values.

  • or
    (or x1 x2 .. xn x) is almost rewritten as (if x1 x1 (if x2 x2 (.. (if xn xn x)))) except that each argument is evaluated at most once.
    Without arguments, returns nil.
  • every?
    Conjonction of predicate values (pred x1) and … and (pred xn)
    Evaluate (pred x) for each x in turn. Return false if a result is nil or false, without evaluating the predicate for the remaining elements. If all test pass, return true.
  • some
    Disjonction of predicate values (pred x1) or … (pred xn)
    Evaluate (pred x) for each x in turn. Return the first result that is neither nil nor false, without evaluating the predicate for the remaining elements. If all tests fail, return nil.
  • and
    Search for first evaluation returning nil or false.
    Without arguments, returns true.

threading

Composition of partially applied functions.

  • ->
    Rewrite x (a a1 a2) .. (b b1 b2) as (b (.. (a x a1 a2) ..) b1 b2)
    If anything else than a list is found where (a a1 a2) is expected, replace it with a list with one element, so that -> x a is equivalent to -> x (list a).
  • ->>
    Like ->, but the arguments describe functions that are partially applied with left arguments. The previous result is inserted at the end of the new argument list.
    Rewrite x (a a1 a2) .. (b b1 b2) as (b b1 b2 (.. (a a1 a2 x) ..)).

trivial

Trivial but convenient functions.

  • inc / dec / zero? / identity
  • gensym
    Generate a hopefully unique symbol.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据操作、用户权限管理等关键技术。 数据设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据设计文件。这些文件通常包括数据结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值