Changeset 3877
- Timestamp:
- 05/25/05 15:02:29 (4 years ago)
- svk:copy_cache_prev:
- 5385
- Files:
-
- 2 modified
-
docs/02Internals.pod (modified) (11 diffs)
-
src/Pugs/Prim/List.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
docs/02Internals.pod
r3804 r3877 59 59 60 60 This section does not discuss the files in detail. Pugs is documented with 61 haddock, and for reference that is the place to look.61 Haddock, and for reference that is the place to look. 62 62 63 63 What this section B<does> provide is an overview of the responsibilities each … … 99 99 table at the bottom. 100 100 101 The table basicall ly says whether the builtin is infix or not, how many101 The table basically says whether the builtin is infix or not, how many 102 102 parameters it accepts, and so forth. 103 103 … … 106 106 This is the file that ties it all together, it takes a Perl 6 file, slurps 107 107 the string out of it, hands it to the parser, then takes the AST out and 108 sends it 's envBody into the evaluator.108 sends its envBody into the evaluator. 109 109 110 110 =head1 A PROGRAM'S LIFE CYCLE IN DETAIL … … 115 115 As we've seen before, the runtime calls the parser on the Perl code, and it, 116 116 in turn, generates an AST. Most parsed things result in trivial structures -- 117 just a representation of the program in something a bit more manipula table117 just a representation of the program in something a bit more manipulable 118 118 than a string of source code. 119 119 120 This basic structure, a node of the AST is called an C<Exp> - an expression.120 This basic structure, a node of the AST, is called an C<Exp> - an expression. 121 121 It represents the combination of values and operation, and the evaluator 122 122 knows to boil it down into a C<Val>. … … 130 130 131 131 The parser is pure in that it does not affect the outside world when it does 132 it 's thing. It constructs the AST, but not much more.132 its thing. It constructs the AST, but not much more. 133 133 134 134 In order to execute things like C<BEGIN> blocks there are exceptions to … … 139 139 This operation has side effects - it causes the world outside the pugs 140 140 interpreter to change. However, it must happen within the "pure" parser, and 141 haskell does not normally allow these things.141 Haskell does not normally allow these things. 142 142 143 143 The C<unsafe> in the name denotes that an effort was made to not care about … … 206 206 207 207 For example C<reduce (Syn "env" [])> is the reduce that takes care of variable 208 declaration using C<VControl>, while C<reduce (Cxt cxt exp)> forces the sub209 expression C<exp> to be evaluated in the context C<cxt>.208 declaration using C<VControl>, while C<reduce (Cxt cxt exp)> forces the 209 subexpression C<exp> to be evaluated in the context C<cxt>. 210 210 211 211 Let's look at some of the more interesting C<reduce>s. My personal favourite is … … 223 223 the body. C<for (@list) { print "i'm the body" }>. 224 224 225 The body is actually a subroutine ,we'll look at that in a bit. After those226 lines are some details which we don't care about right now. Let s pretend they225 The body is actually a subroutine; we'll look at that in a bit. After those 226 lines are some details which we don't care about right now. Let's pretend they 227 227 don't exist and jump down to 228 228 … … 256 256 257 257 The line starting with C<apply> applies the subroutine currently in C<sub'>, 258 and gives it C<these> as it 's paramters on the line starting with C<map>.258 and gives it C<these> as its parameters on the line starting with C<map>. 259 259 260 260 Lastly, after the subroutine is applied, C<runBody> is run again on C<rest>. … … 269 269 C<&runBody>. 270 270 271 When all the auxil lery functions have been define, we can run the body with271 When all the auxiliary functions have been defined, we can run the body with 272 272 the list passed into the for (munging into C<elms> omitted): 273 273 … … 281 281 282 282 283 Subroutine application be very simple, in the case of a C<Prim>. At other283 Subroutine application can be very simple, in the case of a C<Prim>. At other 284 284 times it involves entering a lexical scope, due to block open. Sometimes 285 285 parameter binding is involved too. -
src/Pugs/Prim/List.hs
r3827 r3877 232 232 mapMn' [] _ = return [] 233 233 234 -- | Takes an int and a list and returns a LoL. 235 -- Ex.: 236 -- > list2LoL 3 [1,2,3,4,5] = [[1,2,3],[4,5,undef]] 234 {-| 235 Takes an int and a list and returns a LoL. 236 Ex.: 237 238 > list2LoL 3 [1,2,3,4,5] = [[1,2,3],[4,5,undef]] 239 -} 237 240 list2LoL :: Int -> [Val] -> [[Val]] 238 241 list2LoL n list
