The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
The assignment operator for Signals (And why we need an := operator)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Phil Tomson

Posts: 16
Nickname: philtomson
Registered: Mar, 2006

Phil Tomson is working on strange (and hopefully wonderful) things often Ruby-related.
The assignment operator for Signals (And why we need an := operator) Posted: Mar 13, 2006 3:08 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Phil Tomson.
Original Post: The assignment operator for Signals (And why we need an := operator)
Feed Title: Thoughtfiz
Feed URL: http://wiki.railsplayground.net//xml/rss/feed.xml
Feed Description: Thoughtfiz: lots of tiny thought bubbles, mostly Ruby-related.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Phil Tomson
Latest Posts From Thoughtfiz

Advertisement

I mentioned this briefly at the end of a previous post, but I thought I’d expand on it.

Signal objects can be assigned values. Those values can be of various different types like Bit or even just plain old Integers. In RHDL we’d like the assignment semantics to look a lot like using the built-in = operator (at least at first glance). However, Ruby’s = operator cannot be redefined (and that’s a good thing). So we need some other operator that can be used to indicate assignment of a value to a Signal object. Initially I was using <<, but the problem with that is that << has higher operator precedence than the bitwise logic operators (&,^,| ) which requires that all equations using them be wrapped in parens.

So, I’m moving to using the <= operator for assignement because it has lower operator precedence than the bitwise logic operators. But that solution still isn’t perfect as this is the less-than-equal operator which could cause a problem with mixing-in Comparable into Signal for example. And if I want to test if the value of a Signal object is less-than-or-equal some other object, I’ll need to introduce another function for that (lte – and in order to by smmetrical I’ll need to also introduce gte ).

It would be nice if there were a special assignment operator set asside in Ruby for this very purpose. The := operator wouldn’t need to have any special meaning in Ruby other than as an operator that the programmer could define for these purposes. It would ideally have the same operator precedence as the = operator.

Read: The assignment operator for Signals (And why we need an := operator)

Topic: Smircer, Clone of the Little Tcl IRC Client Previous Topic   Next Topic Topic: C# class extensions: how does it work?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use