This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [] | |
| form-all: func [blk][ | |
| forall blk [blk/1: form blk/1] | |
| blk | |
| ] | |
| types-of: function [value [typeset!]][ | |
| ; typesets don't support reflection | |
| third load mold value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [] | |
| load-any: function [input [string!]][ | |
| out: make block! 100 | |
| junk: none | |
| until [ | |
| result: load/trap/next input 'pos | |
| either error? result/3 [ | |
| append any [junk junk: make string! 20] result/2/1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [] | |
| #system [ | |
| chr: 1 | |
| handle: 0 | |
| KEYDOWN: 0 | |
| KEYUP: 2 | |
| minus-one: -1 | |
| pointer-to-minus-one: :minus-one | |
| rs-phrase: "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [ | |
| author: "Gregg Irwin" | |
| ] | |
| comment { | |
| From Gitter, @this-gavagai asked about modeling in Red compared to modeling | |
| in traditional OOP languages. Here's the concrete example given: | |
| " | |
| Imagine you wanted to simulate economic dynamics in a third world village. You |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [ | |
| Purpose: "Arabic to Roman numbers converter" | |
| Date: "06-Oct-2016" | |
| ] | |
| table: [1000 M 900 CM 500 D 400 CD 100 C 90 XC 50 L 40 XL 10 X 9 IX 5 V 4 IV 1 I] | |
| to-Roman: function [n [integer!]] reduce [ | |
| 'case collect [ | |
| foreach [a r] table [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; A number of languages have `take-while/drop-while` funcs. This is just to show how you | |
| ; can build them in Red. | |
| ; This model can be applied to any function that has a `/part` refinement, or extended in | |
| ; any number of ways. We don't yet have a standard `apply` or `refine` function in Red. | |
| ; Once we do, a more general HOF version could take the action as an arg, as well as the | |
| ; test to apply. | |
| ; Should this return the position, like FIND, rather than an integer? | |
| ; No match would then mean a NONE result. REMOVE/TAKE/COPY with /PART |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [ | |
| Title: "Simple GUI livecoding demo" | |
| Author: "Nenad Rakocevic / Didier Cadieu" | |
| File: %livecode.red | |
| Version: 1.2.1 | |
| Needs: 'View | |
| Usage: { | |
| Type VID code in the bottom right area, you will see the resulting GUI components | |
| rendered live on the left side and fully functional (events/actors/reactors working live). | |
| The top right area let you define Red's values to be used in your VID code, even functions or anything. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [ | |
| File: %greggs-mezz.red | |
| Author: "Gregg Irwin" | |
| Purpose: "An interim mezzanine dump, while Red is still moving fast." | |
| Tabs: 4 | |
| Comment: { | |
| Not everything here has been well-tested or, well, tested. Most | |
| of the functions are ports from R2, with many more to come. I'm | |
| combining everything in one file for ease of experimentation, so | |
| you don't have to worry about includes or dependencies with the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; We have other reflective functions (words-of, body-of, etc.), but | |
| ; this is a little higher level, sounded fun to do, and may prove | |
| ; useful as we write more Red tools. It also shows how to make your | |
| ; own typesets and use them when parsing. | |
| arity-of: function [ | |
| "Returns the fixed-part arity of a function spec" | |
| spec [any-function! block!] | |
| /with refs [refinement! block!] "Count one or more refinements, and add their arity" | |
| ][ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [ | |
| Title: "Tile game" | |
| Purpose: {An implementation in Red of the 4x4 sliding tile puzzle} | |
| Author: "Rudolf W. MEIJER (meijeru)" | |
| File: %tile-game.red | |
| Needs: 'View | |
| Usage: { | |
| Click on any tile that is adjacent to the empty space | |
| and it will shift to that space. | |
| Try to obtain a given configuration, e.g. 1 to 15 in order. |