5 ms·
I've never seen a language with such a variety of built-in data types (e.g. coordinates, tags, email, url, issues). There's support for IPv4 numbers as a base t
by mVChr 10y ago
I've never seen a language with such a variety of built-in data types (e.g. coordinates, tags, email, url, issues). There's support for IPv4 numbers as a base type (tuples) but I can't tell if there's support for IPv6, which shows the trouble with this approach for the language maintainers.
- throwaway7645 10y agoLanguage is still in active and early development, so it could be added. Having primitive types for a lot of things makes for some very short, yet still easy to read code.
- taliesinb 10y agoWhere do you see a nice list of these types?
- throwaway7645 10y agoThe Red website has it somewhere, but they're focusing on the Lang and not the site at the moment, so it might be hard to find. I think the Rebol website (successor language that is mostly compatible although interpreted only) should have a lot of those.
- JadeNB 10y ago> I think the Rebol website (successor language that is mostly compatible although interpreted only) …. I think that this is backwards; Red is inspired by Rebol, which is relatively old: > Red is a computer programming language. Red was made to overcome the limitations of the programming language Rebol. (https://en.wikipedia.org/wiki/Red_(programming_language) https://en.wikipedia.org/wiki/Red_(programming_language) ).
- mapcars 10y agoNo need to go anywhere :) >> words: keys-of system/words >> types: collect [forall words [if datatype! = type? get/any words/1 [keep words/1]]] >> probe types [datatype! unset! none! logic! block! paren! string! file! url! char! integer! float! word! set-word! lit-word! get-word! refinement! issue! native! action! op! function! path! lit-path! set-path! get-path! routine! bitset! point! object! typeset! error! vector! hash! pair! percent! tuple! map! binary! time! tag! email! handle! image! event!]
- greggirwin 10y agoEven easier: help datatype!
- pekr 10y agoIt can't be that easy, or can it? :-)
- tejtm 10y agohere is a list of datatypes from REBOL days, Red is probably mostly there http://compsci.ca/v3/viewtopic.php?t=17726 http://compsci.ca/v3/viewtopic.php?t=17726
- abecedarius 10y agoWhat does a type being built-in do for you extra? In ES6 you can define a template string builder which you could name, for instance, ipv4, and then when you want an IPv4 address literal you say ipv4`192.168.0.1` and get your object. Are there other benefits besides a literal syntax? (Not to slag on Red. One advantage I can see is avoiding the call at runtime to the ipv4 function.)
- greggirwin 10y agoOne of the key reasons for having a lot of literal forms is because REBOL was designed as a messaging language. You can think of it as a data format as much as anything. Template literals in ES6 help with DSL support, which is fundamental in Red's design. It doesn't mean you can just include anything in Red, but the wide array of native forms lets you build a lot of embedded DSLs without resorting to string parsing. Being able to parse at the block level (i.e. datatype level) is really nice. A couple other new features make dealing with non-loadable input easier too. You can use macros to pre-process data, trap errors that `load` triggers and still get back a block of values, or spec some simple rules in `system/lexer/pre-load`. That's another way we might deal with IPv6 values.
- pekr 10y agoYes, a message format. What I would add is, that today ppl are using JSON, not realising, that it is de-facto a Rebol, or at least strongly inspired by Rebol. Well - who wants to use cryptic formats anyway, right? :-)
- greggirwin 10y agoI'll add to my reply, because this is a really good question. Red doesn't have all types in place yet (e.g. date! is coming, and maybe an @ref type, among others), but can still load the following: at 10:00 send gregg@host.dom a link to http://red-lang.org (216.239.32.21) delete %/c/temp/junk.dat assign #DECAFBAD-7337 to John make the main window 800x600 with a color of 255.0.0 answer: yes Here's a quick console session showing what types it found: >> blk: [ at 10:00 send gregg@host.dom a link to http://red-lang.org (216.239.32.21) [ delete %/c/temp/junk.dat [ assign #DECAFBAD-7337 to John [ make the main window 800x600 with a color of 255.0.0 [ answer: yes [ ] == [at 10:00:00 send gregg@host.dom a link to http://red-lang.org (216.239.32.21) delete %/c/temp/junk.dat >> unique collect [foreach val blk [keep type? val]] == [word! time! email! url! paren! file! issue! pair! tuple! set-word!] And you can parse at that level: >> parse blk [ [ some [ [ 'window set val pair! (print ["size:" val]) [ | 'assign set val issue! (print ["issue:" val]) [ | 'link 'to set val url! (print ["link:" val]) [ | skip [ ] [ ] link: http://red-lang.org issue: DECAFBAD-7337 size: 800x600 Of course, you could do something similar in ES6. If you use template literals, your data might look like this: at time`10:00` send email`gregg@host.dom` a link to url`http://red-lang.org` paren`(ipv4`216.239.32.21`)` delete file`%/c/temp/junk.dat` assign issue`#DECAFBAD-7337` to John make the main window pair`800x600` with a color of color`255.0.0` name`answer:` bool`yes` Sorry for getting carried away. :)
- greggirwin 10y agoThe tuple! type supports 3-12 segments, but only 0-255 in each segment, which is a byte. So it's used for colors, IPv4, and can be stretched for custom purposes. IPv6 doesn't have a literal form, though it's been discussed. One of the problems is that lexical space is tight and supporting it specifically may lead to ambiguity with time! values. Also, the colon is an important delimiting character, which makes having hex coded value ambiguous as well.
- eriknstr 10y ago>the colon is an important delimiting character, which makes having hex coded value ambiguous as well In IPv6 or in Red, you mean? In IPv6 the colons are there for convenience only, with the rule being that leading zeros can be omitted and that two or more consecutive groups of all zeros can be replaced with ::. You can only have one instance of :: otherwise it would be ambiguous. For example, the IPv6 address ::1 is actually 0000:0000:0000:0000:0000:0000:0000:0001. Likewise, 2a03:2880:fffe:c:face:b00c:0:35 is actually 2a03:2880:fffe:000c:face:b00c:0000:0035. Once an IPv6 address has been expanded to it's full non-abbreviated form you can safely strip it of colons and use the resulting hexadecimal value to uniquely represent that address. If you were talking about colons in Red and not in IPv6, disregard what I said.
- greggirwin 10y agoI meant if we try to add a literal ipv6 form to Red, but thanks for the info!