syntax, lang = 'sweet', 'ruby'
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

syntax, lang = 'sweet', 'ruby'

check this syntactical sugar from ruby:

@title, @mood, @fulltext = title, mood, fulltext

(Example from _why's amazing online Ruby tutorial: 'Try Ruby in your browser')

Love it!

any chance that 'multiple assignments' can be added to C#? How about VB.Net.Next, hey paul?

Here's an explanation of the above syntax, taken from the Ruby spec:

" Multiple assignment form performs multiple assignment from expressions or an array. Each left hand side expression must be assignable. If single right hand side expression given, the value of the expression converted into an array, then each element in array assigned one by one to the left hand side expressions. If number of elements in the array is greater than left hand sides, they are just ignored. If left hand sides are longer than the array, nil will be added to the locations."





'Paul Bartlett' on Thu, 13 Jul 2006 09:16:43 GMT, sez:

It's especially "sweet" when capturing arguments, e.g.:

(source, dest, *opts) = ARGV

would assign the first argument to "source", the second to "dest" and the rest into the "opts" array.



'mouser' on Thu, 13 Jul 2006 09:19:43 GMT, sez:

assuming this isn't satire, an alternative take:
http://www.donationcoder.com/Forums/bb/index.php?topic=4341



'Matthew Purdon' on Thu, 13 Jul 2006 11:59:30 GMT, sez:

PHP can get close to this functionality with the list function.

http://www.php.net/list

$Beverage= array('coffee', 'brown', 'yes');
list($Name, $Colour, $Caffeinated) = $Beverage;

echo 'Gimme some ',$Name,'!!!';



'Eber Irigoyen' on Thu, 13 Jul 2006 14:24:43 GMT, sez:

I can just see so much misuse and so many ugly bugs because of using this
I don't think is bad, I just think people would misuse it



'Jeffrey Snover' on Fri, 14 Jul 2006 02:28:45 GMT, sez:

Is this the same as what we do in PowerShell?
PS> $a,$b = 1,2,3,4,5
PS> $a
1
PS> $b
2
3
4
5

I use this technique in my response to your query RE: Cascading filetypes.
PS> $filename="MSH.xshd.orig.temp.v1"
PS> $base,$ext=$filename.Split(".")
PS> $base
MSH
PS> $ext
xshd
orig
temp
v1

Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx



'lb' on Fri, 14 Jul 2006 02:32:01 GMT, sez:

thanks for the response Jeffrey!

looks like powershell and ruby are similar but different on this front:
WHile ps has:

PS> $a,$b = 1,2,3,4,5
PS> $a
1
PS> $b
2
3
4
5

I think ruby would have:

RB> $a,$b = 1,2,3,4,5
RB> $a
1
RB $b
2

(See that the left over values are ignored)

both of them have their merits.

i think i like powershell's answer better, because i don't like the idea of data *not* being assigned when you've just tried to assign it.



'Rik Hemsley' on Fri, 14 Jul 2006 07:55:02 GMT, sez:

$a, $b = 1, 2, 3, 4, 5

Here, I'd prefer a syntax error than either the CAR/CDR thing or silently dropping remaining constants.

If something's ambiguous, I don't think it's good to pick the 'best' way, in someone's opinion - much better to force the programmer to explain what they mean.



'Ayende Rahien' on Fri, 14 Jul 2006 08:20:27 GMT, sez:

Try Boo (http://boo.codehaus.org), it works there.



'Marc Stober' on Thu, 27 Jul 2006 14:38:37 GMT, sez:

Same concept is already one of my favorite things about Python.




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. Incivility is not tolerated, such comments are deleted.

 

I'm the co-author of TimeSnapper, a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

I wrote this, and use it every day for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. You should use NimbleText, you handsome devil!

 

Articles

AddDays: A Very Simple Date Calculator AddDays: A Very Simple Date Calculator
Google caught in a lie. Google caught in a lie.
NimbleText 2.0: More Than Twice The Price! NimbleText 2.0: More Than Twice The Price!
A Computer Simulation of Creative Work, or 'How To Get Nothing Done' A Computer Simulation of Creative Work, or 'How To Get Nothing Done'
NimbleText 1.9 -- BoomTown! NimbleText 1.9 -- BoomTown!
Line Endings. Line Endings.
**This** is how you pivot **This** is how you pivot
Art of the command-line helper Art of the command-line helper
Go and read a book. Go and read a book.
Slurp up mega-traffic by writing scalable, timeless search-bait Slurp up mega-traffic by writing scalable, timeless search-bait
Do *NOT* try this Hacking Script at home Do *NOT* try this Hacking Script at home
The 'Should I automate it?' Calculator The 'Should I automate it?' Calculator
aaron swartz: the early works aaron swartz: the early works
Finding (and removing) duplicate files on your hard drive Finding (and removing) duplicate files on your hard drive
Harvey, a .net chat server built with RabbitMQ Harvey, a .net chat server built with RabbitMQ
LeonBambrick.com LeonBambrick.com
So your domain has been stolen. What now? So your domain has been stolen. What now?
kv can remember it for you, wholesale kv can remember it for you, wholesale
Hello IT Department Hello IT Department
Dialog Between a Man and His Vista Laptop Dialog Between a Man and His Vista Laptop
NimbleText 1.6, Codename Jetboat NimbleText 1.6, Codename Jetboat
On Task Hoarding and Todo Bankruptcy On Task Hoarding and Todo Bankruptcy
Developer UI Done Right: Mercurial Commandline! Developer UI Done Right: Mercurial Commandline!
Rediscovering the Amstrad CPC 6128 Rediscovering the Amstrad CPC 6128
Just Wally Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android. A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
Aussie Bushwalking
BrisParks :: best parks for kids in brisbane
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy