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
    评论
MC9S12XEQ512MAL芯片是飞思卡尔公司推出的一款高性能微控制器,具有多个外设模块,其中包括CAN控制器。下面是关于MC9S12XEQ512MAL芯片CAN配置的详细介绍: MC9S12XEQ512MAL芯片的CAN控制器可以通过寄存器来配置。首先,需要设置CAN控制器的工作模式。可以选择单环回模式(Loopback Mode)、自发自收模式(Self-Reception Mode)、静默模式(Listen-Only Mode)以及正常模式(Normal Mode)。 在配置CAN控制器之前,还需要设置CAN的时钟源。MC9S12XEQ512MAL芯片的CAN控制器可以选择外部时钟源或者使用内部时钟源,根据需要进行相应的设置。 接下来,需要配置CAN的位率。MC9S12XEQ512MAL芯片的CAN控制器支持多种位率,根据需要选择合适的位率进行配置。 此外,还需要配置CAN控制器的过滤器。CAN控制器可以设置接收滤波器,用于过滤掉不需要接收的CAN帧,只接收特定的CAN帧。 在CAN控制器配置完成后,可以根据需求选择发送CAN帧或者接收CAN帧。对于发送CAN帧,需要设置CAN消息的标识符、数据长度以及数据内容。对于接收CAN帧,需要设置接收缓冲区,并且可以通过查询或中断方式来读取接收到的CAN帧。 最后,需要配置中断使能位以及相应的中断处理函数。MC9S12XEQ512MAL芯片的CAN控制器支持中断功能,可以在接收到CAN帧或者发送CAN帧完成时触发相应的中断。 以上就是关于MC9S12XEQ512MAL芯片CAN配置的简要介绍。通过对CAN控制器的设置,可以实现CAN通信功能,并根据具体需求进行配置和使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值