我可以清洁repl吗? [英] Can I clean the repl?

查看:19
本文介绍了我可以清洁repl吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 repl 控制台中玩了很多代码,我该如何清除它?我想要一个新的而不重新启动它.可以做到吗?

I have played with a lot of code in a repl console, how can I clear it? I would like a fresh one without restarting it. Can that be done?

推荐答案

如果你想清除你声明的所有临时变量和函数的当前命名空间,你可以使用这个 liner(或创建一个函数):

If you want to clear the current namespace of all temporary variables and functions you declared you can use this one liner (or make a function of it) :

(map #(ns-unmap *ns* %) (keys (ns-interns *ns*)))

(ns myutil)
(defn ns-clean
       "Remove all internal mappings from a given name space or the current one if no parameter given."
   ([] (ns-clean *ns*)) 
   ([ns] (map #(ns-unmap ns %) (keys (ns-interns ns)))))
(ns mytest)

... make loads of junk ...

(myutil/ns-clean)

... great!!! I can now make all new junk ... 

它并不声称为您提供了一个干净整洁的命名空间,只是减少了通常在典型 repl 会话中积累的垃圾.

It does not claim to give you a squeaky clean namespace, just one with less of the junk which usually accumulates in a typical repl session.

谨慎使用:不要从脚下拉出地毯!

Use with caution : do not pull the rug from under your feet!

这篇关于我可以清洁repl吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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