DOCX

Red language back to the programming complexity

By William Sullivan,2015-09-20 21:09
11 views 0
Red language back to the programming complexity

    Red language: back to the programming complexity

    Do you ever feel too confused for software programming stack of chaos?Complex and bloated solution is everywhere, but in both contemporary software to build and maintain links, there are few architects and programmers can truly realize the resulting costs.The existence of Red is in order to counter the complexity, this is it's main design purpose.Yes, in the modern software world, "simple" tools and simple solution still can be reached.Of all of this is to yi trade secrets (this is not a good thing), but since 1997, the solution has actually given by the Rebol programming language.Red inherited from Rebol spectrum, and try to Rebol to greatly expand the scope of application of the original.Red is an ambitious project, it wants to become the first full stack programming language.Here are the main features and design goals:

    ; Paradigm, the default provide functional/imperative paradigm/symbol type

    ; Support based on the prototype object

    ; Same as language (Red language is their own language)

    ; Both in a static way, can also be compiled into native code in a JIT manner

    ; Strong support for concurrent and parallel (by Actor and parallel)

    ; Through the built-in Red/System DSL provide underlying System programming ability

    ; Provide advanced features and REPL console support script

    ; Highly embeddable (like the Lua, or better)

    ; Low memory footprint, support for garbage collection

    ; Low disk space (< 1 MB)

    ; To generate a single command line executable file

    ; Zero installation, zero configuration

    ; Independent of the cross-platform tool chain

    ; In addition to the operation of the operating system, almost no other dependencies

    Red language, just like Rebol, relying on the unique approach to programming, and the idea of the current mainstream language is different.The following is a JSON inventor Douglas Crockford to Rebol language's comments:

    Rebol is a more modern language, but also some very similar with the Lisp thought, mainly embodied in it is fully established prior to data representation, then use it as a program execution.But it has more abundant grammatical materials.Rebol is a brilliant language, it should have been more popular, but not so now, this can lead to shame.

    Red and the Rebol design goal is to provide power of expression, as much as possible while maintaining high readability of the source code, in fact, their source code is very close to natural language.A 2013 will programming language power of expression by the research project, Rebol language ranked third, behind Augeas and Puppet both DSL

    (http://goo.gl/qyPXx).This strongly suggests that, in all general-purpose programming language, Rebol expression ability is the strongest one.Red and Rebol comply with practical

    design principles, no part of it is take the decision of the head, or to vary.Behind every syntax or semantics, with clear design reasons.

    Red language study

    Red and Rebol how to reach such a level of efficiency at the same time, and keep the "simple"?One of the fundamental reason, both because it is both a data format, and a programming language.This feature inherited from Lisp, especially s - concept expression.Lisp has also set up in the Red and the Rebol rely on metaprogramming model.They are the same as the language, all of the code is represented as data.Values stored in the block (use square bracket notation: [...]), the general list, this is the same notation and Lisp, but they do not require a function call for the brackets, this makes the code looks more like a natural language.Function by default USES the prefix notation, however, the Red and the Rebol also support for mathematics and Boolean operator USES the infix notation, it provides a convenient code reading.Adopt the pure metaprogramming in program design, reflection, heat patch, even real-time coding these language features can be built-in support, do not need to learn any new API, also do not need special library support, you just use basic function for data operation.The following is the use of Red language REPL example: $ red

    red>> code: ["hello"]

    == ["hello"]

    red>> insert code 'print

    == ["hello"]

    red>> code

    == [print "hello"]

    red>> do code

    hello

    red>> code/2: 123

    == 123

    red>> code

    == [print 123]

    red>> append code [+ 1]

== [print 123 + 1]

    red>> do code

    124

    red>> length? code

    == 4

    red>> type? code/1

    == word!

    red>> foreach value code [probe type? value]

    word!

    integer!

    word!

    integer!

    As you can see, the basic building blocks of the language are as follows:

    .Value: they represent the Numbers, time, string, the file name and URL, etc., such as 123 45.6 10:20:30. 123 192.168.1.0 "Hello"http://red-lang.org

    .Words: they can be used as a "variable" (but not all), such as print block?The string!The map - each??+ =. .Block: by value, words, and in any order, such as [1 2 3] [123] "ABC" print, and get.

    These are used to represent data, build the expression, definitions, functions, create objects, as well as more complex data structure types of basic building blocks.Symbols are first class (first - class) value, also is a kind of more natural and more effective string substitutes, which are applicable to many cases, especially when involving find operations is more telling, because the symbol can be compared to O (1), whereas string requires O (n).Symbol is case-insensitive, print, print and the print are equivalent, so human language is not like this?

    Rebol or Red program source code is usually a utf-8 input string, they will be the LOAD.LOAD is the core of the native functions, can be any string into contained in a block of memory in the binary format.Blocks to store values to 128 bits of the adjacent cell.Value is mainly divided into scalar value (fixed) its size or sequence values (the user can add/delete data).Numbers, dates, tuples, and value is a scalar value, and value, string, the URL, path,

    documents and the label is sequence value of sample.Scalar value can usually be put into a single storage unit, and sequence value requires additional memory.

    Memory block with recycling is, therefore, manager retention and recovery of the main distribution units.Rebol the classic stop - the - world mark and clean up the garbage collection algorithm, while Red is dependent on the stop - the - thread generational compressed garbage collection algorithm (has not yet been fully implemented), alternating between some or all of The Times.Red will expand its garbage collection algorithm, realize incremental recovery in the future, so that it can be used to develop real-time applications, such as 60 - FPS arcade games.

    Once the source code is loaded into memory and become a value, it is just a pure data.By default, the in sweep through the source code, and make it into Red or when Rebol binary files, will be of value to calculate.If it is in Rebol language, load block will be explained;If it is in Red words, they will be compiled to native code, but the objective is to complete the calculation.Value block in what way to explain, however, is dependent on the context.Interpretive mode has the following kinds:.Functional: take ginseng calculation by a function

    .As a special syntax: the so-called dialect (DSL)

    .By the Parse dialect statement: matching (matching), back (backtrack), as well as generate (production)

    .AD - hoc code: how do you want to handle, is decided by yourself

    .Default (not pure), defined in terms of functional language (i.e., we usually called the "code"), is a kind of language expression, it is very simple semantic rules:

    1. No key

    2. With a known as the "improved" optional extension set and function

    3. Single or multiple values of function arguments and return values

    4. The expression is evaluated from left to right

    5. Infix prefix operator precedence above function calls

    Float of the function layer on the top of the language, therefore, can easily be any custom calculation instead (for example, writing a similar to Prolog interpreter will be very easy).This makes Red and Rebol have excellent ductibility, very easy to adapt to anything you might need.This flexibility is a DSL to become a natural way to solve some computing tasks, through the provision of specific areas of the basis of micro language for a given task to realize optimization.Red and Rebol with this power, the core language and widely used in the standard library embedded DSL:

    1. VID: View Interface Dialect (View Interface the Dialect) is used to establish the GUI DSL

    2. The Draw: DSL for 2 d drawing

    3. Parse the DSL: type a BNF grammar parsing DSL

    4. The Security of the Dialect: a runtime is used to control the Security sandbox feature a DSL

    5. Function specification: a function prototype is described using a DSL

    Make an embedded DSL create easy and convenient factors are:

    1. Parse the DSL: a powerful TDPL and support with recursion, and backtracking

    2. Red or Rebol code can be directly embedded in the rules make sense of it

    3. Rich data types: already support dozens of common data literal notation, so there's no need to

    establish special rules to resolve it

    Here are some GUI DSL in Rebol2 example:

    According to a size of 100 x 100 red button, to open up a window: >> view layout [button "Hello" red 100x100]

    Button will trigger an action:

    >> view layout [button "Hi" [print "Hello!"]]

    The content of the display button, print a field:

    >> view layout [

    in: field 200

    button "Print" [print in/text]

    ]

    A Parse DSL sample in Red language:

     red>> digit: charset "0123456789"

     red>> parse "hello 888 world" [

     some [copy n some digit | skip]

     ]

     red>> n

     == "888"

    Compared with the Rebol, Red bring?

    Because want to solve the Rebol language of some deficiencies, Red language arises at

    the historic moment.These disadvantages include:

    1. Performance high enough (close to Ruby/PHP)

    2. The lack of the underlying programming ability

    3. Can't use multicore, concurrency support is limited

    4. The lack of support for mobile operating system (in 2013 to provide limited support for Android)

    5. Don't open source (open source time only in December 2012, and is limited to Rebol 3rd edition)

    Red in solving the above most have adopted innovative design: embedding a low-level programming language, it can be directly compiled to native code, or Red/System.It USES the Red grammar (the form of value is still the piece), but similar to C, semantic level is lower.It is statically typed language, and provide only a few data types: an integer!And float!And float32!And byte!And logic., the pointer!, struct!, as well as the function!.It is support pointer arithmetic, which gives it to the power of C.The standard library is also very simple, so pure Red/System compiled code size is very small, the following procedures: Red/System [

     Title: "Hello World app"

    ]

    print "Hello World!"

    The compiled usually less than 10 KB.

    Red program is compiled into Red/System code, and links in the standard library and Red, and Red standard library are most Red/System, a small number of written using Red itself.The library is the uncompressed size of about 200 KB.Our goal is to issue in version 1.0, the control of around 500 KB.

    Red with Red/System is tightly integrated, several kinds of methods in Red calls or Red/embedded System code.One of the most useful type is "normal" function, it allows you to define a Red function, the function body is pure Red/System code.Red language will automatically transfer parameters and return values for your packing/unpacking operations.With the help of Red/System, Red language can solve any level of abstraction from the hardware to the DSL, becoming the real first full stack programming language.

    Therefore, Red on Red/System tool chain to generate an executable file.The compiler and linker currently supported target platform include:

    1. CPU: IA - 32, ARMv5 support and limited AVR - 8 (Atmel328P)

    2. File format: PE, ELF, Mach - o,. DLL, so, APK, as well as Windows driver

    3. Plans to support other formats:

    4. Backend: IA - 64, ARMv7, asm. Js, the JVM and the CLR, Dalvik, and LLVM

    5. File format: lib,., a. Ipa, a variety of driver format war (Web archive)

    In addition, Red language also rely on the bridge technology, in order to access like Java virtual machine, especially to provide support for Android.The fact is that now can be Red/Java bridge, using JNI technology from Red remote control program to Java and Android API, and get the return.Later in 2014, we also plans to roll out the Red/Obj - C bridge, to access the iOS and Cocoa API.

    Although the back-end possibility and the combination of the file format is various, but make sure to choose what kind of Red configuration file is short of the target platform.This makes cross-compilation become very simple, such as:

    From the Linux or Mac platforms generates a Windows executable file:

    $ red -t Windows hello.red

    From the Windows platforms generates a Raspberry Pi platforms executable file: $ red -t Linux-ARM hello.red

    The following is about the definition of the target platform:

    Windows [

     OS: 'Windows

     format: 'PE

     target: 'IA-32

     type: 'exe

     sub-system: 'GUI

     ]

    Linux-ARM [

     OS: 'Linux

     format: 'ELF

     target: 'ARM

     type: 'exe

     base-address: 32768 ; 8000h

     dynamic-linker: "/lib/ld-linux.so.3"

     ]

    Red language development work is still a long way to go.Now done its part tool chain USES Rebol2 bootstrap (refers to the language and Red/Red System compiler and linker).Because of the need to support the JIT compiler dynamically generated Red/System code, Red language must have the carrying capacity, so all the tool chain need to rewrite with Red language after version 1.0.New tool chain will be able to generate real to include all the Red language features, and provides two kinds of compiler optimization layer at the same time, generate a smaller, faster code.At present, the Red/System performance measured down about slower than C 4 ~ 6 times, this is good for local code without optimization has.

    Performance will be improved with the upcoming concurrency support.Later this year, Red language will provide a fully asynchronous I/O interface, and the M: N threading model (M a lightweight threads, distribution to the N OS threads).According to the current plan, a higher level of abstraction will use the Actor model, it is to achieve a simple and efficient Shared state synchronization.From a user's point of view, the Actor is a first-class data type, and the use of any other object, little or no additional burden of grammar.However, considering the Go goroutine model fans, we are still consider various options Red language is largely to determine the best model.

    Red language is an open source project, using the BSD license.As the author of the language, I work full time in the already three years.Project funding from users and supporters to donate money.Published for the first time since 2011, to get support is incredible to me.Developers for Red language provides all pleasantly surprised, especially those who understand the Rebol language users.Red language for most of them, including myself, are coveted tools.Red again brought fun to program design language, will be shut out of the complexity, let programmers feel control again, like the 8-bit once experience.

    Start from China

    Because the Red language will have powerful Android support, and particularly suitable for new lines of programmers, we want it to be the world's largest Android market - China.In China, a huge number of programmers and the most brilliant Red contributors to language, there is a programmer thanks sunny days come to Shanghai, China.

    You can download it from http://www.red-lang.org/p/download.html Red

    binaries.Executable file is only half a Megabyte, and contains the whole tool chain, including Red and Red/System language compiler, with an optional console interpreter, and the support of more than 30 types of data of the standard library.You can also try although some old, but relatively complete Rebol2 interpreter, especially when the test GUI DSL.

Report this document

For any questions or suggestions please email
cust-service@docsford.com