乐筑天下

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

[编程交流] (princ) function behavior

[复制链接]

7

主题

18

帖子

11

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-6 06:44:24 | 显示全部楼层 |阅读模式
I have a simple error trap
 
  1. (defun trap1 (errmsg)   (princ "\n An error has occured:\n")   (princ errmsg)   (setvar "blipmode" OLDBLIPMODE)   (setvar "osmode" OLDSNAP)   (setvar "LUnits" OLDLUNITS)   (setvar "LUPrec" OLDLUPREC)   (setvar "cmdecho" oldecho)   (setq *error* temperr)   (princ))
 
The (setq *error* temperr) line is supposed to return the error trap to the original function, stored in temperr. Besides being pretty useless, I noticed the (princ) call at the end was causing a bug - the original error trap was not restored.
 
I am wondering how exactly it happens that having the (princ) line causes this. It is my understanding that the last function evaluated is what is returned from a function, and that calling (princ) returns nil. But why doesn't the side effect of (setq *error* temperr) still happen?
回复

使用道具 举报

91

主题

428

帖子

326

银币

后起之秀

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

铜币
474
发表于 2022-7-6 08:18:39 | 显示全部楼层
I guess the error is not for call to (princ). Should you test the following code?
  1. (defun trap1 (errmsg)(princ "\n An error has occured:\n")(princ errmsg)(if OLDBLIPMODE (setvar "blipmode" OLDBLIPMODE))(if OLDSNAP (setvar "osmode" OLDSNAP))(if OLDLUNITS (setvar "LUnits" OLDLUNITS))(if OLDLUPREC (setvar "LUPrec" OLDLUPREC))(if oldecho (setvar "cmdecho" oldecho))(setq *error* temperr)(princ))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-8-15 20:46 , Processed in 1.611595 second(s), 57 queries .

© 2020-2025 乐筑天下

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