reify,ToString(reify, ToString)
可能很明显,但是给出了这段代码(来自http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/reify ):
(defn reify-str [] (let [f "foo"] (reify Object (ToString [this] f)))) (defn -main [& args] (println (reify-str)) (System.Console/ReadLine))
为什么我得到这个输出?
#<ui$reify_str$reify__4722__4727 foo>
代替:
foo
我在Windows中运行ClojureCLR,如果有帮助的话。 谢谢!
Probably obvious, but given this code (from http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/reify):
(defn reify-str [] (let [f "foo"] (reify Object (ToString [this] f)))) (defn -main [& args] (println (reify-str)) (System.Console/ReadLine))
Why am I getting this output?
#<ui$reify_str$reify__4722__4727 foo>
Instead of:
foo
I'm running ClojureCLR in Windows, if it helps. Thanks!
原文:https://stackoverflow.com/questions/10179780
最满意答案
在您的printStack函数中,您正在清除堆栈。 通过循环并弹出每个项目。
请参阅此处如何打印堆栈项目而不会弹出它们。
在C#中,Stack参数将是一个引用类型,因此在函数中修改它将改变原始Stack。 但是,当Stack实现IEnumerable时,您可以枚举项而不修改原始项。
你可以使用这样的东西
public static string printStack(IEnumerable<string> stack) { string DisplayOutTxt = ""; foreach (var obj in stack) { DisplayOutTxt += obj; } return DisplayOutTxt; }
但要做得更容易
returnStack = string.Join("", stack);
In your printStack function you are clearing the stack. By looping through and popping each item.
Refer to here how you can print your stack items without popping them.
In C# the Stack parameter will be a reference type, so modifying it in a function will mutate the original Stack. But, as the Stack implements IEnumerable, you can enumerate the items without modifying the original.
You could use something like this
public static string printStack(IEnumerable<string> stack) { string DisplayOutTxt = ""; foreach (var obj in stack) { DisplayOutTxt += obj; } return DisplayOutTxt; }
But far more easier would be to do
returnStack = string.Join("", stack);
相关问答
更多-
如果您的应用通过网址意图过滤器启动并创建自己的任务,那么您可以使用 if (isTaskRoot()) { // This activity is at root of task, so launch main activity } else { // This activity isn't at root of task, so just finish() } 编辑:增加了另一种可能的方法 如果您的应用在通过URL意图过滤器启动时启动到现有任务中,则可以执行以下操作: 当您从应用程序中的 ...
-
看看你的循环: while(current_index != target) { holding_stack.Push(stack.Pop()); } 你怎么期望这个循环永远完成? 你不要改变循环体中的target或current_index ...也许你想增加循环中的current_index ? 如果是这样,我可以建议for循环比while循环简单吗? 作为旁注,值得遵循.NET命名约定 - 其中方法是PascalCased ,变量是camelCased ,没有下划线。 所以你最终会得到: f ...
-
强制android没有重启Activity,将android:configChanges添加到AndroidManifest.xml ,是错误的。 记住这一点: 旋转后可能导致堆栈空的原因是什么? 由于Android行为,当您旋转屏幕时,MainActivity将重新启动。 您可以使用AndroidManifest文件的android:configChanges选项覆盖此行为。 android:configChanges="orientation|screenSize" Forcing android t ...
-
因此,您希望使用调用堆栈来实现堆栈数据结构。 这是正常的,在asm中通常是一个好主意。 你不想“清空”调用堆栈,你只想设置一种方法来告诉你何时弹出了你在这个函数中推送的所有数据。 即您的堆栈数据结构为空。 按下代码未生成的标记值,或使用寄存器(或内存位置)保存SP的当前值。 特别是在16位代码中,使用mov bp,sp来制作堆栈帧是很常见的,所以你已经专门用一个寄存器来记住旧的SP值。 您可以在以后的代码中使用cmp sp,bp来查看是否已清空堆栈数据结构。 如果您需要在堆栈上为本地人提供任何空间,您可以设 ...
-
这可能是Firefox 59.0.2中的一个错误,Firefox Nightly 61.0a1(2018-04-23)中已经修复了这个错误。 话虽如此,你只需确定你执行代码的位置。 在Scratchpad内执行代码并在浏览器控制台中检查结果时,它可能无法按预期工作。 虽然当您检查Web控制台时 ,堆栈跟踪显示正确。 或者,也可以在浏览器上下文中运行代码以获得预期的结果。 This is probably a bug in Firefox 59.0.2, which is already fixed in F ...
-
一个简单的计数器应该在这种情况下工作 function doInserts(cb) { MongoClient.connect(url, function(err, db) { if (err) throw err; fs.readDir(path, function(err, files) { var count = files.length; if (count === 0) { db.close(); return cb(); ...
-
Xcode / Stackview,空标签在堆栈视图中吓坏了吗?(Xcode/Stackview, empty labels freaks out in stack view?)[2023-07-20]
这肯定是一个错误。 我复制了你的问题。 在将其添加到我的堆栈视图之前,我能够通过设置每个空间隔标签的高度/宽度来解决它。 这没有意义,因为当您将对象添加到堆栈视图时,它会丢失它所具有的所有约束。 然而,它解决了这个问题: This certainly appears to be a bug. I duplicated your issue. I was able to solve it by setting a height/width to each empty spacer label, prior t ... -
istruc需要结构的名称: istruc wsa_data_struct 请参阅: http : //www.nasm.us/doc/nasmdoc4.html#section-4.12.11 BTW: resd 1需要像resd 1这样的类型。 istruc needs the name of the structure: istruc wsa_data_struct See: http://www.nasm.us/doc/nasmdoc4.html#section-4.12.11 BTW: .si ...
-
堆栈是空的......为什么?(Stack is empty …Why?)[2023-09-16]
在您的printStack函数中,您正在清除堆栈。 通过循环并弹出每个项目。 请参阅此处如何打印堆栈项目而不会弹出它们。 在C#中,Stack参数将是一个引用类型,因此在函数中修改它将改变原始Stack。 但是,当Stack实现IEnumerable时,您可以枚举项而不修改原始项。 你可以使用这样的东西 public static string printStack(IEnumerablestack) { string DisplayOutTxt = ""; foreac ... -
如何创建一个空堆栈?(How to create an empty stack?)[2023-04-30]
你是对的,你所做的就是创建一个指向......的指针,但可能不是stack_t 。 你需要分配一些东西来指出。 见malloc 。 然后你需要将stack_t::top初始化为-1或其他一些值。 零可能在这里不起作用,因为该索引可能是堆栈中的第一项。 You're right, all you've done is created a pointer that points at...something, but probably not a stack_t. You need to allocate so ...