--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
Hi Pete,Thanks for the question. I'm not sure if they've come up in the distant past, but I haven't heard about them recently and I don't think they are on the radar.
Of course, one workaround is to return a list (aka array) (which isn't too bad thanks to Dart's literal list syntax)
num n; string s; [n, s] = [42, "the meaning of life"];
In this case since n and s would be passed by value to the array constructor there would be no way to set them to the proper values right ?
Scala has tuples with up to 22 elements if i'm not mistaken so you can have heterogenous typed "lists" with up to 22 elements.
Regarding destructuring is it possible to override operator = to get that sort of behaviour?
num n; string s; [n, s] = [42, "the meaning of life"];
In this case since n and s would be passed by value to the array constructor there would be no way to set them to the proper values right ?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
function says it returns void. How can it return something if it says it returns nothing?.
--
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Having a whole class declaration is ugly ;-)
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Seth,I have been using Go and I am currently using Dart full time - I find this feature is badly missing.
It's one of those features, I think, once you've had it, you will miss it forever - it makes too much sense, and I'm actually surprised it's not in every major language by now... :-)
Dart is doubly cursed by having none of:
- multiple return values
- reference parameters
- value types/stack structs.
--
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
I'm aware of just a single example where 2 values SHOULD be returned, and cannot be returned through object or any other device for performance reasons. It's divRem.Smart compiler can optimize var a=x~/42, r=x%42 so that only one division actually gets executed. But dart doesn't do it. Neither java.
I think Dart should have tuples where a tuple is an array (or list) with a minimal interface for maximum performance.
Am Freitag, 14. März 2014 17:46:05 UTC+1 schrieb Bob Nystrom:
If I understand your question, the answer is manifest typing and type safety. A product type is a "type" :)
In what respect foo = @(42, "Bar", "Bif") is better than foo=[42, "Bar", "Bif"]?And foo._1 is better than foo[1] ?
--
Tuples are not like lists or sets or queues at all.
Tuples are the fundamental product type - like a struct or a (kinda like a) class. In theory, all you really need is Pair<A,B>, because you can always nest Pairs to add elements Pair<String,Pair<int, bool>>.Check this out. It's basic, old school CompSci :)
In practice most languages support n-tuples. Each tuple arity is a discrete type. They are not like arrays or list of "variable length". So we might have some convenient syntax to create n-tuples like @(42, "Bar") or @("Fu", 42, 68.9, false). Behind the scenes, these are not "tuple-n" types, but instantiations of the generic types Tuple2<A,B> and Tuple4<A,B,C,D>.
There may even be a "convenience syntax" for writing tuple types, such as @(int, String)
instead of Tuple2<int, String>. That's great (and common place).This is why the "array index" syntax for accessing tuple elements is a very bad idea - it leads to the misunderstanding that a tuple is something like a list or array - they are not. They are simple stripped down "structs" (field names are a convenience feature - a good one - in structs). You can't "iterate" through fields of a structure or "record".
Syntax in the general case doesn't matter, but tuples and destructuring and pattern matching all go together in many language design like rum and coke :) You won't generally see too much "field access" of a tuple in SML or languages like that.
But if you really need to access field-n of a tuple, some syntax like this works better and reinforces the basic semantics of the tuple type.foo = @(42, "Bar", "Bif");foo._1>>> 42foo._2>>> 42These are not "indexing" references. They are field references.
Hope that helps.
--
The space of 1-tuples is isomorphic to the space of normal values. The space of 0-tuples is isomorphic to Void.
The space of 1-tuples is isomorphic to the space of normal values. The space of 0-tuples is isomorphic to Void.
--
On Sat, Mar 15, 2014 at 4:27 AM, Thomas Stephenson <ova...@gmail.com> wrote:
The space of 1-tuples is isomorphic to the space of normal values. The space of 0-tuples is isomorphic to Void.Ob-pedantry: The space of 0-tuples has one element, so it's isomorphic to a unit type like Null.(In ML, () is the single element of the "unit" type, and (x) is equivalent to x).
More pedantry:In dart, `void` is a singleton containing the value `null` -- there are no empty sets in a language with null :)
> The null value is not in all types. The `int` type does not contain null ("null is int" -> false). The void type is indeed empty.Woah, wait what? Well slap me and call me Sally. I've considered `is`
to check for `Type \ {null}` and assignments to check for membership
of the type. Since null is an object, I can see it would be simpler if
null were considered a member of it's own type.
var x = null;
//Hint -- checks for `null` should be done with `== null`
if (x is Null) {
print("The `is` operator is not always null-safe");
} else {
print("The `is` operator is always null-safe");
}
I still don't understand why `void` can't be used as a variable type
or generic though... Future<void> would come in useful sometimes and
is consistent, since assignment to the value which completes the
future allows assignment to `null`.
> Future<void> would come in useful sometimes and is consistent
There was a request for `Void` opened and closed here:
> even though I know it won't be allowed any time soon anyway :)
Perhaps you could add a type alias to `dart:core` without requiring any language change, since the goal is to provide better documentation for streams and futures that are 'signals' and actually return `null` ? I just wrote the following in the editor (1.3.0.dev_03_02) and there were no analyzer warnings:```class Void = Null;
> Sorry to say it, but that's a bug in the analyzer. You can't alias a class, only a mixin application. The "with ..." is mandatory. Bug filed: http://dartbug.com/17519Okay :/ But maybe this then?```class _Void {}class Void = Null with _Void;```Or perhaps this is another analyzer bug :)
--
Exercise to reader: find examples where it breaks :-)
@Bob, doesn't printout in your example look completely random? How is (bar)("arg") a getter? Why?I think it's a bug, and it's fixable. (String) example is probably not.
On Fri, Mar 21, 2014 at 1:58 PM, Alex Tatumizer <tatu...@gmail.com> wrote:
There's much simpler example, and closer to the surface of the language.prints:
main() {
print((String).runtimeType);
print(String.runtimeType);
}
_Type
Breaking on exception: object of type NoSuchMethodError
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.