Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why I don't use Ruby.

Reply
Thread Tools

Why I don't use Ruby.

 
 
gabriele renzi
Guest
Posts: n/a
 
      07-14-2004
il Thu, 15 Jul 2004 07:42:31 +0900, Nicholas Van Weerdenburg
<> ha scritto::

>
>gabriele renzi wrote:
>
>>>In Ruby, would it be possible to extend "def" and maybe introduce a
>>>feature called "func" that adds some extra rules to what can be coded?


oh, I see. I don't know how to do this, anyway, but seem possible to
hack to me, even if greatly not efficient
 
Reply With Quote
 
 
 
 
Chris Pine
Guest
Posts: n/a
 
      07-15-2004
All right, I swore I wasn't going to, but no one else seems to be saying it, so...

On Wed, 14 Jul 2004 06:42:48 +0900, Sean O'Dell wrote:
> But within a function, local variables don't affect the return
> value. True, every new function a developer writes could be simply
> nested calls to other functions, but for readability, local
> variables are very helpful, and as long as they're not global or
> stateful, they don't affect the return value, so to the outside
> world it's still just a function.


"...as long as they're not global or stateful..."

But variables are stateful! Plus, in a language where functions can create functions (closures) "global" can be a relative term.

For example, in a purely functional (and fictional) language, this code would be illegal:

foo = {
a = 4
gimmeAnA = { a } # this function just returns `a'
a = 5
gimmeAnA
}

foo.call.call # returns 5, right??

`a' is local to `foo', but is global to `gimmeAnA'. Since the local variable was rebound to 5, which changes what `gimmeAnA', this is not purely functional.

Now, you could fix easily fix this by saying that assignment introduces implicit scope, so there are 2 different variables `a' in 2 different scopes (the second hiding the first), and `gimmeAnA' returns 4, that is, the first `a' in the outer scope. That would be purely functional, but only because you ARE NOT rebinding; you're creating a new binding.

You could do fancier things to allow something which "looks like" looping, but again, in a purely functional way where there really is no rebinding. Syntactically, it can look like just about anything, but sematically there can be no rebinding (excusing context-specific compiler optimizations under the hood, like tail-call optimization).

Chris




 
Reply With Quote
 
 
 
 
Rainer Joswig
Guest
Posts: n/a
 
      07-15-2004
Lennon Day-Reynolds <> wrote in message news:<>.. .
> On Wed, 14 Jul 2004 21:57:20 +0900, Rainer Joswig
> <> wrote:
> > how should the PROD function mentioned in that authoritative explanation
> > work? Looks not very convincing to me. M needs to be incremented
> > in the recursive call - otherwise it would be running for a very
> > LOOOOONG time. Obviously that example code has never been
> > checked.

> Tail-call elimination -- the recursive function will be optimized into
> a loop by the compiler.
>
> Lennon


Hmm

a) it can't be optimized because the function call is not a tail call
(unless the compiler does some other high-level transformations).
b) still some value needs to be changed. the thing just does not compute
a product in any useful way.

Say, if you want to compute a product from 1 to n, you need to
count somewhere. The function in the paper does not.

Here is the recursive version in Lisp:

(defun prod (m n f)
(if (= m n)
m
(* (funcall f m)
(prod (+ 1 m) n f))))

And here is a tail-recursive version:

(defun prod (m n f &optional (acc n))
(if (= m n)
acc
(prod (+ 1 m) n f
(* (funcall f m) acc))))

; product of numbers from 1 to 4
(prod 1 4 #'identity) -> 24
 
Reply With Quote
 
chain_lube@hotmail.com
Guest
Posts: n/a
 
      07-17-2004
Mikael Brockman <> wrote in message news:<>...

> Lots of functional languages lack pattern matching. Scheme, for
> example. One can write Scheme-styled code in Ruby.


Not quite true. Scheme itself lacks any "pattern matching" facility,
though.

However, there is one sound Scheme distribution which includes
pattern-matching: it is called "Bigloo".

Bigloo was also used for the new PhP compiler (see slashdot).

By the way: Bigloo has also types!

I use Bigloo for numerical computations in physics.

Fensterbrett
 
Reply With Quote
 
chain_lube@hotmail.com
Guest
Posts: n/a
 
      07-17-2004
Mikael Brockman <> wrote in message news:<>...

> In Scheme, sum would be:
>
> (define (sum xs)
> (if (null? xs)
> 0
> (+ (car xs) (sum (cdr xs)))))


Or in Bigloo with pattern-matching:

(define (sum xs)
(match-case xs
(() 0)
((?h ???t)
(+ h (sum t)))))


or with types:

(define (sum:bj xs:air)
(match-case xs
(() 0)
((?h ???t)
(+ h (sum t)))))


Bigloo its pattern-matching facility is as sophisticated as OCaml its one.

Fensterbrett
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM
Why, why, why??? =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57