什么时候在clojure(或lisp)中使用感叹号? [英] When to use exclamation mark in clojure (or lisp)?

查看:580
本文介绍了什么时候在clojure(或lisp)中使用感叹号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但我不完全理解不纯函数。他们是

But I don't exactly understand the "impure" functions. Are they


  • 函数更改其参数的状态(通过reset !, alter,java-object-methods,...)

  • 功能发生副作用(例如print,spit,...)

  • 或两者都有?

显然,官方clojure apis没有轰炸每个案件上面。我不知道我应该把它们放在哪里,需要你的帮助,使我的代码更清楚。

Obviously, official clojure apis don't have bang!s on every case above. I wonder when should I put them and need your help to make my code saner.

推荐答案

我会说你不需要对每个不纯的函数放置社区Clojure风格指南建议:

I would say you don't need to put ! on every impure function. Community Clojure Style Guide recommends:


在STM事务中不安全的函数/宏的名称
应以感叹号结束。

The names of functions/macros that are not safe in STM transactions should end with an exclamation mark.

所以,基本上,以结束,改变原子,元数据,vars,瞬变,代理和io的状态。

So, basically, end with ! functions that change state for atoms, metadata, vars, transients, agents and io as well.

感谢@noisesmith的更新。

Thanks to @noisesmith for update.

这篇关于什么时候在clojure(或lisp)中使用感叹号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆