乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 129|回复: 13

[编程交流] Lisp: Extract highest/lowest v

[复制链接]
ajs

16

主题

36

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
80
发表于 2022-7-6 15:08:27 | 显示全部楼层 |阅读模式
O.K, If I have a list,  is there a function that will allow me to extract the highest value and/or lowest value?
 
I don't care about duplicates.
 
In thinking about this, I could probably accomplish this task by using nth values and performing comparisons but that seems tedious. I was hoping I could do it in a single shot with a function.
 
Sample:
 
(setq MyList ((2.00000 26.0000 26.0000 25.6250 25.6250 3.00000 3.00000 2.00000))
 
This is what I'm after:
 
(setq LowVal (MyList))
 
(setq HighVal(MyList))
 
Thanks again for any help
 
---AJS
回复

使用道具 举报

0

主题

269

帖子

279

银币

限制会员

铜币
-4
发表于 2022-7-6 15:15:32 | 显示全部楼层
ajs,
 
From your questions, you really need to get a reference with all the lisp functions to scan through, even search.
 
See 'max & 'min functions....
回复

使用道具 举报

ajs

16

主题

36

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
80
发表于 2022-7-6 15:21:41 | 显示全部楼层
Thanks for the reply. I think you're right about the search function. I do have a function list but sometimes after reading it over and over, I find that I will (through carelessness)  skip over something.
 
An example would be my earlier question on length, for some reason, I thought that the length function applied to strings and thus I didn't examine it properly.
 
I'm going to go online and see if I can find a searchable lisp function list.
 
I do appreciate the help of course. Thank you
 
---AJS
回复

使用道具 举报

0

主题

269

帖子

279

银币

限制会员

铜币
-4
发表于 2022-7-6 15:24:47 | 显示全部楼层
You're welcome.
 
A summary of fiuctions, alphabetical & by category is at http://ronleigh.info/autolisp/acatalog.htm
 
The reference "alispref.pdf" is quite handy, I'd upload it except it's much larger than allowed at this site, maybe you can find it elsewhere...
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 15:28:11 | 显示全部楼层
  1. Command: (apply 'min '(4 6 1 8 0.5 12))0.5Command: (apply 'max '(4 6 1 8 0.5 12))12.0
回复

使用道具 举报

0

主题

2

帖子

2

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 15:31:46 | 显示全部楼层
The function MAX doesn´t seem to work with a already defined list of reals, eg:
 
Command: !(Setq A '(1.0 1.2 2.1 3.4))
(1.0 1.2 2.1 3.4))
 
Command: !(Max A)
; error: bad argument type: numberp: (1.0 1.2 2.1 3.4)
 
Command: !(Apply 'Max A)
; error: bad argument type: numberp: (1.0 1.2 2.1 3.4)
 
Any sugestion??
回复

使用道具 举报

4

主题

940

帖子

961

银币

初来乍到

Rank: 1

铜币
12
发表于 2022-7-6 15:37:08 | 显示全部楼层
Worked for me
 
回复

使用道具 举报

5

主题

194

帖子

193

银币

初来乍到

Rank: 1

铜币
24
发表于 2022-7-6 15:43:43 | 显示全部楼层
Hey ajs
 
There is no need to use the ! if you are defining a function on the command line
 
 
Just use as lpseifert has shown
 
回复

使用道具 举报

0

主题

119

帖子

119

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 15:47:46 | 显示全部楼层
I don't mean to hijack this thread, but (somewhat related) how would I obtain values that are repeated in a list?
 
e.g. (setq list1 (a b b c)) - how do you extract the value of b?
回复

使用道具 举报

0

主题

2

帖子

2

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 15:52:46 | 显示全部楼层
Thanks, for help.
 
The function work fine. I had a problem, because my list has a 'nil' element.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 19:15 , Processed in 0.947051 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表