乐筑天下

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

[编程交流] can't figure this out

[复制链接]

78

主题

207

帖子

129

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
395
发表于 2022-7-6 11:54:57 | 显示全部楼层 |阅读模式
I have this code
 
  1.   (setq FPname (cond ((getstring (strcat "\nF-Part to insert : ")))            (FPname)))
In this code FPname is a global variable.  This way it is remembered the next time I use this lisp.  so it would work like this
 
1st time run
 
"f-Part to insert >: "  i might enter 1234
 
2nd time run
 
"f-part to insert : "  I just press enter
 
Right now if I press enter FPname goes to nill.  This worked for me before in this lisp
 
  1. (setq ANG_L2 (cond ((getdist (strcat "\nSpecify size of second leg : ")))           (ANG_L2)))
but it is just slightly different.  In this one i was using integers and in the first one i'm using a string.  any thoughts?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:09:02 | 显示全部楼层
You won't be able to use the same construct with getstring.
 
Whereas getint, getreal etc return nil on null input, getstring will return an empty string (i.e. non-nil).
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:20:38 | 显示全部楼层
Something like would suffice:
 
  1. (or *def* (setq *def* "Default"))(or (eq "" (setq tmp (getstring t (strcat "\nString  : "))))   (setq *def* tmp))
Or
 
  1. (or *def* (setq *def* "Default"))(setq *def* (cond ((= "" (setq tmp (getstring (strcat "\nString  : ")))) *def*)                 (tmp)))
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 12:34:31 | 显示全部楼层
Maybe a little old fashion but I still prefer a more straight forward approach.
 
  1. [b][color=BLACK]([/color][/b]setq def_input [color=#2f4f4f]"Default"[/color][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]while [b][color=FUCHSIA]([/color][/b]or [b][color=NAVY]([/color][/b]not input[b][color=NAVY])[/color][/b]            [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]snvalid input[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]        [b][color=FUCHSIA]([/color][/b]setq input [b][color=NAVY]([/color][/b]getstring [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nString Input :   "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]        [b][color=FUCHSIA]([/color][/b]cond [b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b]= input [color=#2f4f4f]""[/color][b][color=MAROON])[/color][/b]  [b][color=MAROON]([/color][/b]setq input def_input[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
 
 
This gives you unlimited  ( or ) and ( cond ) testing and is a bit more readable to me.  My $0.02.  -David
回复

使用道具 举报

78

主题

207

帖子

129

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
395
发表于 2022-7-6 12:44:05 | 显示全部楼层
 
wow that makes total sense.  thanks so much
回复

使用道具 举报

78

主题

207

帖子

129

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
395
发表于 2022-7-6 12:48:50 | 显示全部楼层
very interesting.  so many ways to get the same result.  I do appreciate your guys help. Is there a place to submit lisps on this site? i'd like to submit what I've done with this sites help.  Maybe it can help others.
 
btw is there any purpose to using the asterisks around *def* ?  I noticed it with some code I got from an error handler where they used *error*.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 13:02:34 | 显示全部楼层
 
I use asterisks in Global variables just to make them "less common" to avoid clashes with other programs. In essence, a global variable could be named in the same fashion as a local one, but if two programs use the same global variable, there could be undesired consequences.
 
*error* is something completely different, it is AutoCAD's user-definable error handling function.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 10:18 , Processed in 0.409396 second(s), 77 queries .

© 2020-2025 乐筑天下

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