Clojure学习:运行在 Java 虚拟机(JVM)上的动态Lisp编程语言

ops/2024/10/20 11:32:50/

因为HY的学习资料较少,所以通过学习Clojure来辅助学习HY。前期也看过一些Common Lisp和On Lisp的文档,现在还不太清楚HY跟谁最接近。

文档:Clojure - Getting Started

在FreeBSD下安装Clojure

在FreeBSD系统,可以直接使用pkg进行安装,先用pkg search查看安装包的名字:

# pkg search cloj
pkg: No SRV record found for the repo 'FreeBSD'
clojure-1.11.1.1200_1          Dynamic programming language for the JVM
clojure-cider-1.15.0_1         Clojure IDE and REPL for Emacs
clojure-cider-emacs_canna-1.15.0_1 Clojure IDE and REPL for Emacs
clojure-cider-emacs_devel-1.15.0_1 Clojure IDE and REPL for Emacs
clojure-cider-emacs_devel_nox-1.15.0_1 Clojure IDE and REPL for Emacs
clojure-cider-emacs_nox-1.15.0_1 Clojure IDE and REPL for Emacs
clojure-cider-emacs_wayland-1.15.0_1 Clojure IDE and REPL for Emacs
clojure-mode.el-5.11.0_14,1    Emacs lisp module for the Clojure language
clojure-mode.el-emacs_canna-5.11.0_14,1 Emacs lisp module for the Clojure language
clojure-mode.el-emacs_devel-5.11.0_14,1 Emacs lisp module for the Clojure language
clojure-mode.el-emacs_devel_nox-5.11.0_14,1 Emacs lisp module for the Clojure language
clojure-mode.el-emacs_nox-5.11.0_14,1 Emacs lisp module for the Clojure language
clojure-mode.el-emacs_wayland-5.11.0_14,1 Emacs lisp module for the Clojure language
swank-clojure-1.2.1            Swank/SLIME support for Clojure

发现有Clojure,用pkg install 进行安装

# pkg install clojure
Updating FreeBSD repository catalogue...
pkg: No SRV record found for the repo 'FreeBSD'
Fetching meta.conf:   0%
FreeBSD repository is up to date.
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):New packages to be INSTALLED:clojure: 1.11.1.1200_1rlwrap: 0.45.2_1Installed packages to be REINSTALLED:liblz4-1.9.4_1,1Number of packages to be installed: 2
Number of packages to be reinstalled: 1The process will require 20 MiB more space.
17 MiB to be downloaded.Proceed with this action? [y/N]: y
[1/2] Fetching rlwrap-0.45.2_1.pkg: 100%  114 KiB 116.9kB/s    00:01    
[2/2] Fetching clojure-1.11.1.1200_1.pkg: 100%   17 MiB   1.8MB/s    00:10    
Checking integrity... done (0 conflicting)
[1/3] Installing rlwrap-0.45.2_1...
[1/3] Extracting rlwrap-0.45.2_1: 100%
[2/3] Reinstalling liblz4-1.9.4_1,1...
[2/3] Extracting liblz4-1.9.4_1,1: 100%
[3/3] Installing clojure-1.11.1.1200_1...
[3/3] Extracting clojure-1.11.1.1200_1: 100%

 安装好后,使用clj命令进入clojure交互界面:

$ clj
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.pom from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.pom from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.pom from central
Downloading: org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar from central
Downloading: org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar from central
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.jar from central
Clojure 1.11.1
user=> 

学习Clojure

写一个hello world demo

Clojure">
user=> (defn hello-world [username](println (format "Hello, %s" username)))(hello-world "world")
#'user/hello-world
user=> user=> Hello, world
nil

 Clojure的特点:

跟其它语言相比比较有特点的是分数,比如可以直接这样写:22/7 ,这个分数可以直接使用。

字符串可以前面加#来构成正则表达式

#"[0-9]+"

四种数据

Clojure">'(1 2 3)     ; list
[1 2 3]      ; vector
#{1 2 3}     ; set
{:a 1, :b 2} ; map

Clojure Evaluation

 

Structure vs Semantics

 

交互模式

交互模式下×1 ×2 ×3 分别代表最近的三次返回值

  • *1 (the last result)

  • *2 (the result two expressions ago)

  • *3 (the result three expressions ago)

 

Clojure - Install Clojure

 


http://www.ppmy.cn/ops/56272.html

相关文章

优秀策划人必逛的地方,你不会还不知道吧?

道叔今天依然记得当初刚入行的时候,每天为完成策划任务,焦虑的整晚睡不着觉的痛苦。 但其实……很多时候,选择比努力更重要 优秀的策划和文案,也从来不是天生,你要走的路,前人都已经走过,你要做的仅仅是整…

ARIES,数据恢复算法,万变不离其宗...

今天来聊两个问题: 1. 如果缓冲池(buffer pool)满了,哪些数据页(page)要刷盘,哪些数据页不刷盘? 2. 数据库崩了,怎么利用检查点(checkpoint)与预写…

SQL AND OR 运算符的使用与区别

SQL AND & OR 运算符的使用与区别 SQL(Structured Query Language)是一种用于管理关系数据库的编程语言。在SQL中,AND和OR运算符用于在WHERE子句中组合条件,以便更精确地筛选数据。本文将详细介绍SQL中的AND和OR运算符,包括它们的使用方法和区别。 1. SQL AND 运算符…

telegram Bot 设置左下角的菜单按钮

我们在和BotFather对话的时候发现它的左下角有个菜单按钮,而且里面有很多命令,这个是怎么实现的了?接着往下看 也不知道CSDN是什么问题,关于telegram的几篇文章都没有审核通过,有想法了解更多的可以去我的博客南锋去看…

利用亚马逊云科技云原生Serverless代码托管服务开发OpenAI ChatGPT-4o应用

今天小李哥继续介绍国际上主流云计算平台亚马逊云科技AWS上的热门生成式AI应用开发架构。上次小李哥分享​了利用谷歌云serverless代码托管服务Cloud Functions构建Gemini Pro API​,这次我将介绍如何利用亚马逊的云原生服务Lambda调用OpenAI的最新模型ChatGPT 4o。…

Flutter【组件】标签

简介 flutter 标签组件。标签组件是一种常见的 UI 元素,用于显示和管理多个标签(或标签集合)。 github地址: https://github.com/ThinkerJack/jac_uikit pub地址:https://pub.dev/packages/jac_uikit 使用方式&…

MSPM0G3507——超声波模块移植代码

超声波没有做单独的代码文件 直接自己创建.c.h文件,将这些复制粘贴即可,然后进行SYSCFG配置按照这些配置即可,有啥问题直接评论区提出,如果看不懂的话评论区说一下,再出讲解 超声波.c文件 #include "ti_msp_dl…

【MySQL】MySQL索引失效场景

文章目录 前言一、说明举例1. 函数操作与索引失灵2. 数据类型错配3. LIKE操作符与通配符的陷阱4. OR逻辑运算的索引挑战5. 复合索引与最左前缀规则6. 特定比较操作符的局限 二、总结 前言 在数据库管理和优化的天地里,索引如同图书的目录,极大地加速了数…