English 中文(简体)
是否有可能在咖啡方面产生代号?
原标题:Is it possible to do code generation in Coffeescript?

Say I有一些咖啡用具(有 Underscore.js混合)。

someData =
  hello:  haha 
_(3).times (index) ->
  someData["key-#{index}"] = index

<代码>tData的价值为:

hello:  haha 
key-0: 0
key-1: 1
key-2: 2

如果咖啡包有某种合成糖,允许我写像这样的东西,那是ice的:

    someData =
      hello:  haha 
<%
    _(3).times (index) ->
%>
      key-#{index}: index

产生<代码>,其价值与原数值相同。

是否有这样的咖啡设施?

问题回答

短期答复:无

更长的答复: 这种合成物将超越咖啡的原意,而咖啡的用意是,一种简单的语言,与 Java文一样,为1:1。 然而,你可以在咖啡厅顶上使用另一种排外语。 事实上,用铁路3.1,它用粗略的直截了当的手法,可以使用鲁比拉的代号来制定咖啡代典,与你的假设一样。

补充 Trevor的回答:法典的产生(a la Lisp)确实是强大的,但你也可以建立一些基本抽象的结构。 例如(使用:

data = _(
  hello:  haha 
).merge(_([0..2]).mash (x) -> ["key-" + x, x])




相关问题
How do you set the class of an object to something else?

I ve seen this recently and now I can t find it … How do you set the class of an object to something else? --Update: Well, in Pharo! Like: d:=Object new. d setClass: Dictionary. Only that it isn ...

Using Polymorphic Code for Legitimate Purposes?

I recently came across the term Polymorphic Code, and was wondering if anyone could suggest a legitimate (i.e. in legal and business appropriate software) reason to use it in a computer program? ...

How can I get this snippet to work?

I d like to port a little piece of code from Ruby to Groovy, and I m stuck at this: def given(array,closure) { closure.delegate = array closure() } given([1,2,3,4]) { findAll { it > 4} ...

Why can t I use attr_accessor inside initialize?

I m trying to do an instance_eval followed by a attr_accessor inside initialize, and I keep getting this: ``initialize : undefined method attr_accessor `. Why isn t this working? The code looks kind ...

热门标签