MAL“标准库”

news/2024/4/23 23:09:07/文章来源:https://blog.csdn.net/weixin_41871524/article/details/132000729

MAL“标准库”

    • alias-hacks
    • benchmark
    • equality
    • load-file-once
    • memoize
    • perf
    • pprint
    • protocols
    • reducers
    • test_cascade
    • threading
    • trivial

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.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_337241.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

kali Linux 工具 BurpSuite-暴力破解

关于渗透的实验,我们大多数能在kali的工具集找到,其中关于抓包工具BurpSuite的使用,我做一个比较简单的实验————————暴力破解—————————— 暴力破解,顾名思义,就是我们把密码一个个尝试,只…

【MySQL】索引特性

​🌠 作者:阿亮joy. 🎆专栏:《零基础入门MySQL》 🎇 座右铭:每个优秀的人都有一段沉默的时光,那段时光是付出了很多努力却得不到结果的日子,我们把它叫做扎根 目录 👉没…

ReID网络:MGN网络(1) - 概述

Start MGN 1. 序言 现代基于感知的信息中,视觉信息占了80~85%。基于视觉信息的处理和分析被应用到诸如安防、电力、汽车等领域。 以安防市场为例,早在2017年,行业咨询公司IHS Market,我国在公共和私人领域安装有摄像头约1.76亿…

docker启动容器报错

报错信息 [rootDream soft]# docker run -it -d -p 8080:8080 tomcat eec9fab6b9ca06d2bbf1467aef05d8020ee60448978e10ac20c38888934f0a0b docker: Error response from daemon: driver failed programming external connectivity on endpoint hungry_euclid (163242f0079e72…

数值分析第五章节 用Python实现解线性方程组的直接解法

参考书籍:数值分析 第五版 李庆杨 王能超 易大义编 第5章 解线性方程组的直接解法 文章声明:如有发现错误,欢迎批评指正 文章目录 引言与预备知识高斯消去法列主元消去法 矩阵三角分解法杜利特尔分解法平方根法 向量和矩阵的范数误差分析 引言…

Python 进阶(五):os 模块

❤️ 博客主页:水滴技术 🌸 订阅专栏:Python 入门核心技术 🚀 支持水滴:点赞👍 收藏⭐ 留言💬 文章目录 1. 文件和目录的基本操作1.1 获取当前工作目录1.2 更改当前工作目录1.3 获取目录下所有…

qssh使用

到官网下载qssh的源码QSsh-botan-1,使用qtcreator打开后,直接编译,即可得到qssh的库 头文件将QSsh-botan-1\src\libs\ssh目录下的.h文件拷到include文件夹下,即为库头文件。 qssh有个问题,如果你将qssh的类放在子线程…

致敬图灵!HashData拥抱数据智能新时代!

图1:2023ACM中国图灵大会现场 生于1912年的艾伦图灵被称为“计算机科学之父”、“人工智能之父”。1966年,国际计算机协会(ACM)为了纪念这位卓越的科学家,设立了以其名字命名的ACM图灵奖,以表彰在计算机领…

MySQL | 常用命令示例

MySQL | 常用命令示例 一、启停MySQL数据库服务二、连接MySQL数据库三、创建和管理数据库四、创建和管理数据表五、数据备份和恢复六、查询与优化 MySQL是一款常用的关系型数据库管理系统,广泛应用于各个领域。在使用MySQL时,我们经常需要编写一些常用脚…

【初阶C语言】整数比大小

各位大佬的光临已是上上签 在C语言刷题过程中,一定遇到过很多比大小的题目,那么本节就专门介绍比大小的方法,若大佬们还有更优解,欢迎补充呀! 本节讲解的方法主要有三种:1.条件判断 2.三目操作符 3.函数调…

干翻Dubbo系列第四篇:Dubbo3第一个应用程序细节补充

前言 不从恶人的计谋,不站罪人的道路,不坐亵慢人的座位,惟喜爱耶和华的律法,昼夜思想,这人便为有福!他要像一棵树栽在溪水旁,按时候结果子,叶子也不枯干。凡他所做的尽都顺利。 如…

14 Linux实操篇-进程管理(重点)

14 Linux实操篇-进程管理(重点) 文章目录 14 Linux实操篇-进程管理(重点)14.1 进程的基本操作14.1.1 进程和程序14.1.2 父进程和子进程14.1.3 常见的Linux进程14.1.4 显示系统执行的进程-ps14.1.5 终止进程-kill/killall14.1.6 查…

36.悬浮板

悬浮板 html部分 <div class"container"><div class"square"></div> </div>css部分 *{margin: 0;padding: 0; } body{background-color: #111;height: 100vh;overflow: hidden;display: flex;justify-content: center;align-it…

【小白必看】Python爬虫实战之批量下载女神图片并保存到本地

文章目录 前言运行结果部分图片1. 引入所需库2. 发送请求获取网页内容3. 解析网页内容并提取图片地址和名称4. 下载并保存图片完整代码关键代码讲解 结束语 前言 爬取网络上的图片是一种常见的需求&#xff0c;它可以帮助我们批量下载大量图片并进行后续处理。本文将介绍如何使…

机器学习 | Python实现NARX模型预测控制

机器学习 | Python实现NARX模型预测控制 目录 机器学习 | Python实现NARX模型预测控制效果一览基本介绍研究内容程序设计参考资料效果一览 基本介绍 机器学习 | Python实现NARX模型预测控制 研究内容 贝叶斯黑盒模型预测控制,基于具有外源输入的非线性自回归模型的预期自由能最…

绝美!轮到AI写真爆火了!18种AI视频制作教程;Llama 2微调的极速指南;Nijijourney官方AI绘画课 | ShowMeAI日报

&#x1f440;日报&周刊合集 | &#x1f3a1;生产力工具与行业应用大全 | &#x1f9e1; 点赞关注评论拜托啦&#xff01; &#x1f916; 摄影写真面临AI技术洗牌&#xff0c;一键生成杂志大片的时代来了 软件&#xff1a;midjourney & Stable Diffusion 模型&#xff…

TypeScript基础篇 - TS模块

目录 模块的概念 Export 语法&#xff08;default&#xff09; Export 语法&#xff08;non-default&#xff09; import 别名 Type Export语法【TS】 模块相关配置项&#xff1a;module【tsconfig.json】 模块相关配置项&#xff1a;moduleResolution 小节总结 模块的…

【LLM】大语言模型学习之LLAMA 2:Open Foundation and Fine-Tuned Chat Model

大语言模型学习之LLAMA 2:Open Foundation and Fine-Tuned Chat Model 快速了解预训练预训练模型评估微调有监督微调(SFT)人类反馈的强化学习(RLHF)RLHF结果局限性安全性预训练的安全性安全微调上手就干使用登记代码下载获取模型转换模型搭建Text-Generation-WebUI分发模型…

pytorch的发展历史,与其他框架的联系

我一直是这样以为的&#xff1a;pytorch的底层实现是c(这一点没有问题&#xff0c;见下边的pytorch结构图),然后这个部分顺理成章的被命名为torch,并提供c接口,我们在python中常用的是带有python接口的&#xff0c;所以被称为pytorch。昨天无意中看到Torch是由lua语言写的&…

M 芯片的 macos 系统安装虚拟机 centos7 网络配置

centos 安装之前把网络配置配好或者是把网线插好 第一步找到这个 第二步打开网络适配器 选择图中所指位置 设置好之后 开机启动 centos 第三步 开机以后 编写网卡文件保存 重启网卡就可以了&#xff0c;如果重启网卡不管用&#xff0c;则重启虚拟机即可 “ ifcfg-ens160 ” 这…