TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Lispy - Code-as-data in Ruby, without the metaprogramming madness.

90 点作者 chrislloyd大约 14 年前

16 条评论

raganwald大约 14 年前
I like it, and I speak as someone who is slowly recovering from a year in a sanatorium gibbering about how I killed Mozart by using a library to decompile Ruby into sexps, then rearranged the sexps before reconstructing Ruby code:<p><a href="https://github.com/raganwald/rewrite_rails" rel="nofollow">https://github.com/raganwald/rewrite_rails</a><p>I'd still be in a padded cell if I hadn't run into a doctor who eschewed the more complex forms of therapy and simply told me to stop doing that.
bguthrie大约 14 年前
I really, really like this idea. It's difficult enough to employ Ruby's metaprogramming constructs without making a mess, so the idea of instantly decomposing into nested lists is really appealing.<p>I realize the library is only, like, three days old, but questions/feedback:<p>- Do the DSL methods get turned into into proper Ruby methods eventually? I'd hate to see this whole thing built on the back of method_missing.<p>- Picking apart nested arrays can lead to its own kind of spaghetti code. When people build DSLs, I recommend they immediately turn their high-level method calls into nicely testable objects. Can we see an example of that here?<p>- The author specifically calls out libraries like ActiveRecord, which would suggest that the primary use case for this library is for integration as a DSL layer into your own libraries, but he doesn't provide any examples of that usage--just Lispy.new. I'd like a way to extend Lispy into my own class or module and get that same functionality.
评论 #2459062 未加载
pavelludiq大约 14 年前
OT: I'm very tempted to be an asshole smug lisp weenie, and make some Greenspun's rule joke, but instead I'm going to try to be helpful. Ruby hackers pride themselves for being early adopters of new and cool technology, learning new skills, and libraries. What I've failed to notice is any interest in the old technologies, from which ruby got most of its good ideas(lisp, smalltalk). There is tremendous value in learning from the past(a lot of really good ideas didn't make it to the "cool kids languages" of today). This isn't specific to ruby, but its a good example. So my attempt at useful advice is: do learn lisp, instead of reinventing the wheel badly.<p>Anyway, I've been thinking about this kind of stuff, and it seemed like a good opportunity to mention it.
评论 #2460129 未加载
评论 #2461978 未加载
KirinDave大约 14 年前
I'm a bit confused what this has to do with lisp. Seems more like a classic Smalltalk building pattern. If it's a reference to "code as data" from the Lisp tradition (which is a friendlier colloquialism for "homoiconicity"), then they bear only a tenuous relationship.<p>Which is not to say that this library wouldn't be useful. But it is to say that it doesn't really bring any of the power of homoiconicity or consequential techniques thereof to Ruby.
sleight42大约 14 年前
The man has a point. We should consider using sexps more often when developing internal DSLs.<p>That's not to say (stupid iPad) that we dont still need define_method and instance_eval; however, decoupling the language definition/API from the language impl is good sauce.
extension大约 14 年前
I called this a Domain Agnostic Language:<p><a href="http://code.extension.ws/post/169602795/dal-rb" rel="nofollow">http://code.extension.ws/post/169602795/dal-rb</a><p>I don't actually like the approach though. Ruby makes DSLs as easy as "normal" interfaces. Why not take advantage of that? Generating and parsing an AST is exactly the kind of extra complexity that Ruby lets you avoid.
评论 #2459165 未加载
评论 #2459634 未加载
JonnieCache大约 14 年前
<i>Ruby metaprogramming hell (it is a real place).</i><p>But meta-sin is so much fun!<p>Nice lib with a lot of potential. It will definitely come in handy and may well prompt me to take some unfinished projects off the back burner and get them in the oven as it were.<p>Also, I enjoy your README writing style. It walks the fine line between amusing irreverence and technical specificity very well.
评论 #2460755 未加载
评论 #2459962 未加载
评论 #2459271 未加载
zwp大约 14 年前
From the Examples:<p><pre><code> fart =&#62; [ :fart, [] ] fart 1 =&#62; [ :fart, 1 ] fart 1, 2 =&#62; [ :fart, [ 1, 2 ] ] </code></pre> Why isn't the single argument call:<p><pre><code> fart 1 =&#62; [ :fart, [ 1 ] ] </code></pre> ?<p>ps. this is also fun: <a href="http://parsetree.rubyforge.org/ruby_parser/" rel="nofollow">http://parsetree.rubyforge.org/ruby_parser/</a>
评论 #2459798 未加载
samps大约 14 年前
This looks pretty cool, but as a non-Rubyist, I remain confused about the purpose of all these "DSL" libraries that lispy aims to simplify.<p>In the examples, at least, the language was only used to declaratively build hierarchical list/dictionary structures. The only constructs I can see used are blocks and method invocations; there aren't any loops or conditionals or anything else imperative. Can someone more experienced with Ruby DSLs explain what lispy accomplishes that something like YAML or a simple custom parser doesn't? (Other than a bunch of extra "do"s and ":"s.)
评论 #2460780 未加载
jamesbritt大约 14 年前
How does this compare to the 'sexp' library?<p><a href="http://www.artima.com/rubycs/articles/patterns_sexp_dslsP.html" rel="nofollow">http://www.artima.com/rubycs/articles/patterns_sexp_dslsP.ht...</a>
soamv大约 14 年前
I see that lispy is using instance_exec -- which means that the scope of code inside that code is the lispy instance, which might not be what the programmer expects. For example if he does this inside a method he'd find his instance variables missing. (Is that right, or am I misreading the code?)<p>You could use some sort of global or thread local variable to maintain the context, and then you wouldn't lose the instance scope, but then this code will not mix well with yield (and continuations and fibers etc.)<p>So then it looks like the only way to solve this problem really neatly is in a language that has macros.<p>(I made some attempts at this problem too, at <a href="https://github.com/soam/blox" rel="nofollow">https://github.com/soam/blox</a> . It is slightly more complex than lispy; see for example <a href="https://github.com/soam/blox/tree/master/samples/webservice" rel="nofollow">https://github.com/soam/blox/tree/master/samples/webservice</a> .)
mardigan大约 14 年前
There was a recent ruby-talk announcement for live parse trees being available in 1.9 now. Presumably gives the functionality of ParseTree. <a href="http://quix.github.com/live_ast" rel="nofollow">http://quix.github.com/live_ast</a>
helium大约 14 年前
This is very close to something I built earlier this year...just nicer.<p><a href="https://github.com/michael-erasmus/Flippant" rel="nofollow">https://github.com/michael-erasmus/Flippant</a>
kleiba大约 14 年前
<i>Saying that, I've written about 10 lines of LISP in my life. Pete keeps telling me to go read SICP and I keep meaning to but then I end up at the local bar listening to some rock band and I'm like "crap, it's 3am".</i><p>Man, you're such a rebel!!
moron4hire大约 14 年前
"Code-as-data in Ruby, without the metaprogramming madness. — Read more <a href="http://www.youtube.com/watch?v=aD4bn5pp32w" rel="nofollow">http://www.youtube.com/watch?v=aD4bn5pp32w</a><p>link is a rickroll. What was the point of that? I don't think we need to be super serious about everything, but at least don't be anti-productive. I was hoping to have a link to a talk or screen-cast demonstrating what Lispy was about. Instead, backwards rickroll.
评论 #2461173 未加载
评论 #2461388 未加载
jcapote大约 14 年前
1000 internets to this man. This is excellent!