This one was also met with loud applause last night's Dallas usergroup presentation. Scorpio supports implicit array and structure creation. Here are some simple examples, first array:
<!--- CFMX7 code --->
<CFSET myArray=ArrayNew(1)>
<CFSET ArrayAppend(myArray, "Adam")>
<CFSET ArrayAppend(myArray, "Ben")>
<CFSET ArrayAppend(myArray, "Tim")>
<!--- In Scorpio you can use this code --->
<CFSET myArray=["Adam","Ben","Tim"]>
Here's how it works for structures:
<!--- CFMX7 code --->
<CFSET myStruct=StructNew()>
<CFSET myStruct.product="ColdFusion">
<CFSET myStruct.version=8>
<!--- In Scorpio you can use this code --->
<CFSET myStruct={product="ColdFusion", version=8}>
Oh and once again, thanks for a great presentation last night.
Mike.
structNew should be structNew()... right?
Will this new syntax also work in cfscript?
Regs,
/t
Steven
I love it. Pretty soon, I'll have to do double-takes to make sure I'm looking at my JavaScript code or my CFScript code. :-)
For example, would the code below automatically convert this string to a structure?
<cfset myStructSTRING='{product="ColdFusion", version=8}'>
<cfset myStruct=myStructSTRING>
How would you go from a CFML struct back to the JSON string?
What you've shown is just a simple assignment, and naturally, any quoted string on the right side of an assignment becomes a string in the left hand variable, and your string remains so in both assignments. (I suppose perhaps if this was a function, it might be able to take a string and coerce it into something else. )
I'll leave it to others with more experience in the new JSON functionality in Scorpio to elaborate on whether your desired conversion (either direction) might be done with some other new functionality (if it can yet be discussed publicly). Hope that's helpful.
looks like CFMX8 is focused on the coders and administrators this time. yay!
It's even more bizarre that you're saying CF8 (may?) have direct support for JSON *and* this almost-JSON syntax.
CF8:
{product="ColdFusion", version=8}
vs:
JSON:
{"product" : "ColdFusion", "version" : 8}
Why two different variations? Ben any thoughts?
<cfset myStructSTRING='{product="ColdFusion", version=8}'>
<cfset myStruct=Evaluate(myStructSTRING)>
That would blow my mind! :-D I'm not even sure if that would be useful, but it would be cool. :-)
--- Ben
This is how object literals work in other languages, isn't that what CF8 is trying to allow?
--- Ben
<CFQUERY ARGUMENTSCOLLECTION="{name="myQuery", datasource="myCSN} ">
...
</CFQUERY>
(btw, I'm not a cf developer. Mostly flex, and from the looks of it, this is closer and closer to what I'm familiar with)
First, let me say that I couldn't get it to work as you propose. Now, you were missing a closing quote before your closing brace, but that's not the reason. I first used that new script-based struct-building code to create a struct, and confirmed it worked (dumped the struct it created). I then tried to use the same right-hand code (the brace-enclosed code) from that assignment to put into the ArgumentsCollection. It failed to compile. I tried all forms of quotes and pounds, to no avail.
I also tried to put it in the VAR attribute of CFDUMP. It just wouldn't work. I also tried using evaluate. Maybe someone else can find a way to make it work.
Even then, the "heck no" part of my reply is that I surely don't hope to see this style catch on. :-) Building a struct within an attribute of a tag this way seems very unusual, at least to a CF developer's eyes. I realize you're saying it seems flex-y. Still, I'd ask it it's really solving any problem or perhaps just creating more confusion. That's just my opinion, of course.