clisp的一些function
;; example: (write (A-Z :start (+ 65 1) :end 87))
(defmacro A-Z (&key (start 65) (end 90))
(let* ((s-start (gensym))
(s-end (gensym))
(s-start start)
(s-end end))
`(loop for i from ,s-start to ,s-end
collect (code-char i))))
(defmacro A-Z (&key (start 65) (end 90))
(let ((s-start (gensym))
(s-end (gensym)))
`(let ((,s-start ,start)
(,s-end ,end))
(loop for i from ,s-start to ,s-end
collect (code-char i)))))
(defun prime-p (n)
"判读n是否为素数"
(when (> n 1)
(do ((i 2 (1+ i)))
((= i n) t)
(when (zerop (mod n i))
(return nil)))))
(defun typeof (obj)
"return the type of OBJ"
(typecase obj
(list 'list)
(number 'number)
(array 'array)
(function 'function)
(string 'string)))
(defun our-filter (lst fn)
;; 这个过滤器感觉更 remove差不多
(let ((res nil))
(dolist (el lst)
(let ((is (funcall fn el)))
(if (not is) (push el res))))
(nreverse res)))
(defun _sort (lst)
;;; 这是一个默认从小到大的排序函数
;;; > (setf a '(1 3 2))
;;; (1 3 2)
;;; > (_sort a)
;;; (1 2 3)
;;; > a
;;; (1 2 3)
(let ((len (length lst)))
(do ( (i 0 (+ i 1)) ) ( (not (< i len)) )
(do ( (j 0 (+ j 1)) ) ( (not (< j (- len 1 i))) )
(let (
(a (nth j lst))
(b (nth (+ j 1) lst))
)
(and (> a b)
(setf (nth (+ j 1) lst) a
(nth j lst) b
)))))) lst)
(defun distinct (lst)
;;; 去除重复数据
;;; > (distinct '(1 2 3 2 1 6))
;;; (1 2 3 6)
(let ((res '()))
(dolist (el lst)
(if (not (member el res))
(setf res (append res (cons el nil)))
))
res))
(defun our-push (lst &rest addData)
;; 返回新的lst
;; > (our-push '(1 23) 'name "hello" '(a bc))
;; (1 23 NAME "hello" (A BC))
(dolist (el addData)
(setf lst (append lst (cons el nil))))
lst)
(defun our-length (lst)
;;; 这个函数返回一个lst的长度
(if (null lst)
0
(+ 1 (our-length (cdr lst)))
))
(defun our-qa ()
;;; 一个询问1+1等于几的函数
(format t "1+1= ")
(let ((a (read)))
(if (and (numberp a) (= a 2))
'yes
(our-qa)
)
))
(defun null-list (lst)
;;; 若果是空表返回 t
(if (and (listp lst) (null lst))
t))
(defun our+ (numberlist)
;;; 这个函数会对 一个全是数字的列表进行求和
;;;> (our+ '(1 2 3 "233"))
;;;6
(let ( (firstNumber (car numberlist)) )
(if (or (null numberlist) (null (numberp firstNumber)))
0
(+ firstNumber (our+ (cdr numberlist)))
)
)
)
clisp的一些function的更多相关文章
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- jsp中出现onclick函数提示Cannot return from outside a function or method
在使用Myeclipse10部署完项目后,原先不出错的项目,会有红色的叉叉,JSP页面会提示onclick函数错误 Cannot return from outside a function or m ...
- JavaScript function函数种类
本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通函数:介绍普通函数的特性:同名覆盖.arguments对象.默认返回值等. 2. 匿名函数:介绍匿名函数的特性:变量匿名函数.无名称匿名函数. ...
- 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()
1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...
- jquery中的$(document).ready(function() {});
当文档载入时执行function函数里的代码, 这部分代码主要声明,页面加载后 "监听事件" 的方法.例如: $(document).ready( $("a") ...
- Function.prototype.toString 的使用技巧
Function.prototype.toString这个原型方法可以帮助你获得函数的源代码, 比如: function hello ( msg ){ console.log("hello& ...
- 转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38
转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38http://space.itpub. ...
- [Xamarin] 透過Native Code呼叫 JavaScript function (转帖)
今天我們來聊聊關於如何使用WebView 中的Javascript 來呼叫 Native Code 的部分 首先,你得先來看看這篇[Xamarin] 使用Webview 來做APP因為這篇文章至少講解 ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
随机推荐
- WPF设计模式下选定数据源?F12直达ViewModel的方法,超好用
您只需要在xaml上新增这一行代码,记得引用对应命名空间哦 d:DataContext="{d:DesignInstance viewModel:LoginViewModel, IsDesi ...
- 题解 UVA11694 【Gokigen Naname谜题 Gokigen Naname】
题目 题解 考场上连暴力都不会打的码农题,深搜是真的难 /kk 前置问题 怎么输出"\" cout<<"\\"; 2.怎么处理不在一个环里,可以考虑 ...
- NOIP2020 移球游戏
Description 给定 \(n+1\) 个栈,前 \(n\) 个栈内有不定的 \(m\) 个元素,最后一个栈为空,每个栈的最大容量为 \(m\) 每种颜色都有 \(m\) 种,求任意一种方法,使 ...
- RESTFul应用分析
Restful API 近年来应用越来越广泛,各大互联网公司纷纷推出了自己的 Restful API 服务. 本文将从实际应用出发,从 REST 到 Restful 再到 Restful API ,逐 ...
- WAAPI+Python使用中的相关问题和学习记录
首先鸣谢:溪夜大佬的博客:https://blog.audiokinetic.com/zh/everyone-can-use-waapi-overview/ 本文环境: Wwise 2019.1.9. ...
- docker(11)Dockerfile 中的COPY与ADD 命令
前言 Dockerfile 中提供了两个非常相似的命令 COPY 和 ADD,本文尝试解释这两个命令的基本功能,以及其异同点,然后总结其各自适合的应用场景. Build 上下文的概念 在使用 dock ...
- Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
- 牛客小白月赛17 G 区间求和
传送门 题意: 题解: 原本想着使用暴力方法: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream& ...
- A - 你能数的清吗 51Nod - 1770
题目: 演演是个厉害的数学家,他最近又迷上了数字谜.... 他很好奇 xxx...xxx(n个x)*y 的答案中 有多少个z,x,y,z均为位数只有一位的整数. 大概解释一下: 22222*3 = ...
- 2019 ICPC Asia Taipei-Hsinchu Regional Problem K Length of Bundle Rope (贪心,优先队列)
题意:有\(n\)堆物品,每次可以将两堆捆成一堆,新堆长度等于两个之和,每次消耗两个堆长度之和的长度,求最小消耗使所有物品捆成一堆. 题解:贪心的话,每次选两个长度最小的来捆,这样的消耗一定是最小的, ...