首页 \ 问答 \ reify,ToString(reify, ToString)

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
更新时间:2022-12-06 14:12

最满意答案

在您的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(); ...
  • 这肯定是一个错误。 我复制了你的问题。 在将其添加到我的堆栈视图之前,我能够通过设置每个空间隔标签的高度/宽度来解决它。 这没有意义,因为当您将对象添加到堆栈视图时,它会丢失它所具有的所有约束。 然而,它解决了这个问题: 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 ...
  • 在您的printStack函数中,您正在清除堆栈。 通过循环并弹出每个项目。 请参阅此处如何打印堆栈项目而不会弹出它们。 在C#中,Stack参数将是一个引用类型,因此在函数中修改它将改变原始Stack。 但是,当Stack实现IEnumerable时,您可以枚举项而不修改原始项。 你可以使用这样的东西 public static string printStack(IEnumerable stack) { string DisplayOutTxt = ""; foreac ...
  • 你是对的,你所做的就是创建一个指向......的指针,但可能不是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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。