- 浏览: 648250 次
- 性别:
- 来自: Shanghai
文章分类
最新评论
-
107x:
不错,谢谢!
Vim多行缩进技巧 -
can007:
EC2是不负责储存???
体验Amazon EC2 -
vanxining:
书名是什么呢?
Neural Network依然不是理想的AI -
贾懂凯:
缩进的标准是tab,linux默认tab=8。在不同的平台会出 ...
Vim多行缩进技巧 -
edison0951:
貌似他的老师是波谱尔吧,和黑天鹅讲的东西差不多
索罗斯与因果论
Rocaml lets you wrtie Ruby extension in Ocaml. It can be a relief to my project, I truely hope. We are using Ocaml with Rails by means of fork or socket and dealing with the format of communication between two sides is just boring.
Now let's have a look at how rocaml works. I'm gonna translate an example in rubyinline to rocaml. Since rubyinline supports basic type transaltion between Ruby and C, the orginal example is forced to declare a lot of complex data type defined in ruby.h by hand:
comparing to Ocaml code:
and then we only have to declare a simple function interface in extconf.rb:
Unfortunately though the ocaml code is more clear than the C one without being polluted by all kinds of type constants, the benchmark shows the rocaml extension is about 5 times slower than the C one. It seems the type conversion is still pricy considering Ocaml code generally should be on the same page with C in terms of speed.
没听说过。你被一群 ruby 网站的菜鸟忽悠了。如果说要接近“自然语言”,Ruby 中没有任何有关自然语言语法的内容,Perl 才是“自然语言”;要说接近英语,Ruby 不就是允许函数调用少个括号+访问拦截器好用一点+一点不完善的标识符字符集扩展吗?别忘了还有 Smalltalk 那个变态……
世界不全是对象化的也不全是函数化的,这是真的…
Now let's have a look at how rocaml works. I'm gonna translate an example in rubyinline to rocaml. Since rubyinline supports basic type transaltion between Ruby and C, the orginal example is forced to declare a lot of complex data type defined in ruby.h by hand:
require 'rubygems' require 'inline' class Check class << self inline do |builder| builder.c_raw " static VALUE check(int argc, VALUE *argv, VALUE self) { double x = NUM2DBL(RARRAY(argv[1])->ptr[0]); double y = NUM2DBL(RARRAY(argv[1])->ptr[1]); int len = RARRAY(argv[0])->len; double last_x = NUM2DBL(RARRAY(RARRAY(argv[0])->ptr[len-1])->ptr[0]); double last_y = NUM2DBL(RARRAY(RARRAY(argv[0])->ptr[len-1])->ptr[1]); double cur_x, cur_y = 0.0; int i, c = 0; for (i = 0; i < len; i++) { cur_x = NUM2DBL(RARRAY(RARRAY(argv[0])->ptr[i])->ptr[0]); cur_y = NUM2DBL(RARRAY(RARRAY(argv[0])->ptr[i])->ptr[1]); if ((((cur_y <= y) && (y < last_y)) || ((last_y <= y) && (y < cur_y))) && (x < (last_x - cur_x) * (y - cur_y) / (last_y - cur_y) + cur_x)) { c = !c; } last_x = cur_x; last_y = cur_y; } if (c == 1) return Qtrue; return Qfalse; } " end end end
comparing to Ocaml code:
let check polygon point = let len = Array.length polygon in let last = polygon.(len - 1) in let result = ref false in for i = 0 to (len - 1) do let current = polygon.(i) in if ((current.(1) <= point.(1) && last.(1) > point.(1)) || (last.(1) <= point.(1) && current.(1) > point.(1))) && (point.(0) < ((last.(0) -. current.(0)) *. (point.(1) -. current.(1)) /. (last.(1) -. current.(1)) +. current.(0))) then begin result := not !result end; last.(0) <- current.(0); last.(1) <- current.(1) done; !result open Callback let _ = register "Check.check" check
and then we only have to declare a simple function interface in extconf.rb:
Interface.generate("check") do def_module("Check") do fun "check", [ARRAY(ARRAY(FLOAT)), ARRAY(FLOAT)] => BOOL end end
Unfortunately though the ocaml code is more clear than the C one without being polluted by all kinds of type constants, the benchmark shows the rocaml extension is about 5 times slower than the C one. It seems the type conversion is still pricy considering Ocaml code generally should be on the same page with C in terms of speed.
评论
6 楼
cookoo
2007-07-21
恩,这个要看语言开发者的开发理由和本人习惯了。
5 楼
Lich_Ray
2007-07-21
一个语言,到底是 user-friendly 是首要的呢,还是 powerful?如果要说“人性化设计”,这个就没准了;我自己还设计过一种自动把命名为主动动词的单参数方法转换为参数以被动方式调用的访问拦截器。但可能,这种东西做到语言中不太合适;如果能非常完美地整合到开发环境中,Smalltalk/Squeak 倒是个不错的想法,但怎么看怎么有点“超现实主义”。
Perl 不矛盾,只是语言学家对语言的抽象和我们“普通人”有点不同。
Perl 不矛盾,只是语言学家对语言的抽象和我们“普通人”有点不同。
4 楼
cookoo
2007-07-21
这是我自己使用Ruby快3年来的感觉。不仅仅指Ruby语法上的DSL能力(当然这个其实很简化,和真正能完全改变语法的meta programming不能比),更包括Ruby的API人性化设计风格,比如故意重复同一功能的不同名字减少记忆负担, 比如2.weeks.ago这种语法。任何语言对使用者来说都要求语法掌握和API掌握两方面,Ruby是唯一让我经常可以感受不翻文档直接猜中API这种奇妙感觉的语言。你如果只从语法规范上研究语言恐怕难以感受到使用语言的实际感觉。
Perl的设计哲学虽然以自然语言为蓝本,可惜太多设计不一致的符号把它污染了,这种内在矛盾性让我难以理解。
Perl的设计哲学虽然以自然语言为蓝本,可惜太多设计不一致的符号把它污染了,这种内在矛盾性让我难以理解。
3 楼
Lich_Ray
2007-07-20
引用
Ruby是最接近自然语言(英语)的程序语言
没听说过。你被一群 ruby 网站的菜鸟忽悠了。如果说要接近“自然语言”,Ruby 中没有任何有关自然语言语法的内容,Perl 才是“自然语言”;要说接近英语,Ruby 不就是允许函数调用少个括号+访问拦截器好用一点+一点不完善的标识符字符集扩展吗?别忘了还有 Smalltalk 那个变态……
世界不全是对象化的也不全是函数化的,这是真的…
2 楼
cookoo
2007-07-20
呵呵,可以理解。
我觉得Haskell是最接近数学语言的程序语言,而Ruby是最接近自然语言(英语)的程序语言。各有各的用处,世界不全都是对象化的也不全都是函数化的。
可惜从以前的实验的情况看Haskell现在还不足以让我放心用到项目里,只好退而求其次了。
我觉得Haskell是最接近数学语言的程序语言,而Ruby是最接近自然语言(英语)的程序语言。各有各的用处,世界不全都是对象化的也不全都是函数化的。
可惜从以前的实验的情况看Haskell现在还不足以让我放心用到项目里,只好退而求其次了。
1 楼
Lich_Ray
2007-07-19
被 Haskell 迷得神魂颠倒,遂对 ML 家族其他成员失去兴趣;又对 Ruby 之流没有兴趣,结果对 rocaml 没有兴趣...
发表评论
-
Idiom of using in F#
2007-02-21 10:18 2449In Don Syme's excellent book dr ... -
天生一对
2007-01-10 02:29 3860Born to be together,这句也是Apple以前 ... -
FP中减少括号的语法糖
2006-12-30 07:35 5230在F#中内置了两个很有用的运算符 |> 和 >&g ... -
Functional programming has finally reached the masses by VB
2006-12-06 06:40 2919Confessions of a Used Programmi ... -
List comprehension和递归的巧妙结合
2006-11-18 05:10 5472我以前总以为list comprehension这个语法糖不过 ... -
[fwd]Why I Chose Erlang
2006-11-13 03:23 2860Why I chose erlang (very, very ... -
Practical Ocaml阅读笔记5-8章
2006-11-11 04:40 23451. Marshal从文件读出来的东西不包括类型信息,需要手动 ... -
Univ. Washington video course: Programming Languages
2006-11-03 08:33 2876http://www.cs.washington.edu/ed ... -
Practical Ocaml阅读笔记1-4章
2006-11-02 00:20 36611. 重定义类型并不会出警告?(不对吧?) 2. int是3 ... -
One-day Compiler in Ocaml
2006-10-30 07:25 3486Happen to find this nice presen ... -
Why Function Programming is Important to Financial Modeling?
2006-02-22 19:28 2704(Quoted from LexiFi)LexiFi foun ... -
Hasekll Road to Future
2006-07-05 00:14 2321Several friends have asked me a ... -
Pratical Ocaml作者采访
2006-10-24 21:20 3313Practical Ocaml是Apress最近新书。我还在观 ... -
GHC 6.6宣布支持SMP
2006-10-23 05:45 2783Haskell工业级编译器GHC 6.6版本刚刚发布,重要更新 ... -
[fwd]什么是Monad?
2006-10-11 07:37 9889发信人: faint (faint), 信区: FuncPro ... -
游戏开发者眼中的未来开发语言
2006-10-03 02:51 5173The Next Mainstream Programming ... -
ICFP2006大赛结果
2006-09-23 04:59 4891International Conference on Fun ... -
Darcs简介
2006-09-14 14:59 7015Darcs 是新一代轻量级分布式版本控制系统. 完全使用Has ... -
对Erlang向Web领域发展的一些看法
2006-09-14 14:20 4065Erlang的传统优势领域是分布系统。Erlang在web应用 ...
相关推荐
《A First Book of C++ 4th Edition》是一本针对初学者的经典C++编程教材,旨在引导读者逐步掌握C++语言的基础知识和编程技巧。第四版的更新通常意味着作者已经根据最新的C++标准和教学实践进行了修订,以适应当前的...
A First Book of ANSI C PPT Chapter 1 Introduction to Computer Programming
A First Book of ANSI C PPT Chapter 2 Getting Started in C Programming
Leonid Fridman, Jaime H. Moreno, Rafael Iriarte,等. Sliding Modes after the First Decade of the 21st Century[M]. Springer Berlin Heidelberg, 2012.
A First Book of C++ (Introduction to Programming) By 作者: Gary J. Bronson ISBN-10 书号: 1111531005 ISBN-13 书号: 9781111531003 Edition 版本: 4 出版日期: 2011-02-11 pages 页数: 802 Gary Bronson’s A ...
first_day_of_school
根据提供的文件信息,这是一本名为《Fundamentals of Python: First Programs》的电子版图书,作者为Kenneth A. Lambert,其中Martin Osborne作为贡献作者参与了编写工作。该文档属于综合文档类型,并且由于OCR扫描...
The first page Google rankings is what this eBook will strive to provide for you and it will offer you with hidden Google secrets which can help your web site or pages to rank well on search results....
A FIRST COURSE IN PROBABILITY高清pdfA FIRST COURSE IN PROBABILITY高清pdfA FIRST COURSE IN PROBABILITY高清pdf
After this first taste of the capabilities of ggplot2, you will explore in detail the visualization approach implemented in this package, the so-called grammar of graphics, providing you with the ...
The Elements of Computing Systems Building a Modern Computer from First Principles 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
This is the first book specifically designed to offer the student a smooth transitionary course between elementary fluid dynamics (which gives only last-minute attention to turbulence) and the ...
The first lock consists of a panel filled with sparkling aems:diamondsrubies.emeraldsand so onBeside the panel is a row of buttonsone corresponding to each type of gem.To unlock the doorLin must press...
A First Course in Abstract Algebra (6th Edition) by John B.Fraleigh
如:Template Method、Command、Iterator、Observer、State、Strategy、Mediator、Visitor、Interpreter、Memento、Chain of Responsibility。 结构型模式可以让你把类或对象组合到更大的结构中。如:Decorator、...
在标准C++库中使用find_first_of以及 find_first_not_of的使用举例。 已知有如下string对象: “ab2c3d7R4E6” 编写程序寻找该字符串中所有的数字字符,然后再寻找所有的字母字符。以 两种版本编写该程序:第一个...
本知识点主要涉及"find"、"first of all"和"flash"这三个词汇的详细解释和应用。 首先,"find"是一个非常常用的动词,有多种含义。它可以表示偶然发现某个物品或情况,如例句中的"She found a wallet lying on the ...
Head First Android Development cuts through the fog of dozens of components, hundreds of API calls and focuses on the core skills you need. Do you want a book that is more than simply a reproduction ...
当Y1,Y2,…..,Yi-1都 能推出ε, (1), 而Yi推不出ε,则FIRST(Y1)--{ε},FIRST(Y2)--{ε},……,FIRST(Yi-1)--{ ε}, FIRST(Yi) 都属于 FIRST(X)。 5. 当4中所有的 Yi都能推出ε,(i=1,2,….n),则 FIRST(X)=FIRST(Y1)...