| 
									
										
										
										
											2009-01-22 20:07:44 -05:00
										 |  |  | ! Copyright (C) 2005, 2009 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  | USING: accessors arrays assocs classes colors colors.constants | 
					
						
							| 
									
										
										
										
											2011-09-15 17:40:37 -04:00
										 |  |  | combinators combinators.smart compiler.units definitions | 
					
						
							| 
									
										
										
										
											2013-03-10 12:11:18 -04:00
										 |  |  | definitions.icons effects fry generic hash-sets hashtables | 
					
						
							|  |  |  | help.stylesheet help.topics io io.styles kernel locals make math | 
					
						
							|  |  |  | namespaces parser present prettyprint prettyprint.stylesheet | 
					
						
							|  |  |  | quotations see sequences sequences.private sets slots sorting | 
					
						
							|  |  |  | splitting strings urls vectors vocabs vocabs.loader words | 
					
						
							|  |  |  | words.symbol ;
 | 
					
						
							| 
									
										
										
										
											2009-05-16 05:26:45 -04:00
										 |  |  | FROM: prettyprint.sections => with-pprint ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: help.markup | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-26 19:23:19 -04:00
										 |  |  | PREDICATE: simple-element < array | 
					
						
							| 
									
										
										
										
											2008-09-06 20:13:59 -04:00
										 |  |  |     [ t ] [ first word? not ] if-empty ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: last-element | 
					
						
							|  |  |  | SYMBOL: span | 
					
						
							|  |  |  | SYMBOL: block | 
					
						
							| 
									
										
										
										
											2009-10-01 13:12:54 -04:00
										 |  |  | SYMBOL: blank-line | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : last-span? ( -- ? ) last-element get span eq? ;
 | 
					
						
							|  |  |  | : last-block? ( -- ? ) last-element get block eq? ;
 | 
					
						
							| 
									
										
										
										
											2009-10-01 13:12:54 -04:00
										 |  |  | : last-blank-line? ( -- ? ) last-element get blank-line eq? ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ?nl ( -- )
 | 
					
						
							|  |  |  |     last-element get
 | 
					
						
							|  |  |  |     last-blank-line? not
 | 
					
						
							|  |  |  |     and [ nl ] when ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-04 07:17:54 -04:00
										 |  |  | : ($blank-line) ( -- )
 | 
					
						
							| 
									
										
										
										
											2016-03-29 20:14:42 -04:00
										 |  |  |     nl nl blank-line last-element namespaces:set ;
 | 
					
						
							| 
									
										
										
										
											2009-10-04 07:17:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : ($span) ( quot -- )
 | 
					
						
							|  |  |  |     last-block? [ nl ] when
 | 
					
						
							| 
									
										
										
										
											2016-03-29 20:14:42 -04:00
										 |  |  |     span last-element namespaces:set | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     call ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: print-element ( element -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: simple-element print-element [ print-element ] each ;
 | 
					
						
							|  |  |  | M: string print-element [ write ] ($span) ;
 | 
					
						
							| 
									
										
										
										
											2009-02-09 02:47:31 -05:00
										 |  |  | M: array print-element unclip execute( arg -- ) ;
 | 
					
						
							|  |  |  | M: word print-element { } swap execute( arg -- ) ;
 | 
					
						
							| 
									
										
										
										
											2014-05-19 13:18:48 -04:00
										 |  |  | M: effect print-element effect>string print-element ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | M: f print-element drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : print-element* ( element style -- )
 | 
					
						
							|  |  |  |     [ print-element ] with-style ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : with-default-style ( quot -- )
 | 
					
						
							| 
									
										
										
										
											2020-02-15 01:18:38 -05:00
										 |  |  |     default-style get swap with-nesting ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : print-content ( element -- )
 | 
					
						
							|  |  |  |     [ print-element ] with-default-style ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ($block) ( quot -- )
 | 
					
						
							| 
									
										
										
										
											2009-10-01 13:12:54 -04:00
										 |  |  |     ?nl | 
					
						
							| 
									
										
										
										
											2016-03-29 20:14:42 -04:00
										 |  |  |     span last-element namespaces:set | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     call
 | 
					
						
							| 
									
										
										
										
											2016-03-29 20:14:42 -04:00
										 |  |  |     block last-element namespaces:set ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Some spans | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $snippet ( children -- )
 | 
					
						
							|  |  |  |     [ snippet-style get print-element* ] ($span) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-05 19:29:29 -04:00
										 |  |  | ! for help-lint | 
					
						
							|  |  |  | ALIAS: $slot $snippet | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $emphasis ( children -- )
 | 
					
						
							|  |  |  |     [ emphasis-style get print-element* ] ($span) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $strong ( children -- )
 | 
					
						
							|  |  |  |     [ strong-style get print-element* ] ($span) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $url ( children -- )
 | 
					
						
							| 
									
										
										
										
											2017-10-23 19:55:41 -04:00
										 |  |  |     [ ?second ] [ first ] bi [ or ] keep >url [ | 
					
						
							| 
									
										
										
										
											2011-03-07 18:03:48 -05:00
										 |  |  |         dup present href associate url-style get assoc-union
 | 
					
						
							|  |  |  |         [ write-object ] with-style | 
					
						
							| 
									
										
										
										
											2008-09-29 05:09:02 -04:00
										 |  |  |     ] ($span) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $nl ( children -- )
 | 
					
						
							| 
									
										
										
										
											2009-10-01 13:12:54 -04:00
										 |  |  |     drop nl last-element get [ nl ] when
 | 
					
						
							| 
									
										
										
										
											2016-03-29 20:14:42 -04:00
										 |  |  |     blank-line last-element namespaces:set ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Some blocks | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : ($heading) ( children quot -- )
 | 
					
						
							| 
									
										
										
										
											2009-10-01 13:12:54 -04:00
										 |  |  |     ?nl ($block) ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $heading ( element -- )
 | 
					
						
							|  |  |  |     [ heading-style get print-element* ] ($heading) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $subheading ( element -- )
 | 
					
						
							|  |  |  |     [ strong-style get print-element* ] ($heading) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ($code-style) ( presentation -- hash )
 | 
					
						
							| 
									
										
										
										
											2008-04-13 23:58:07 -04:00
										 |  |  |     presented associate code-style get assoc-union ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : ($code) ( presentation quot -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2009-09-08 12:43:47 -04:00
										 |  |  |         code-char-style get [ | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |             last-element off
 | 
					
						
							| 
									
										
										
										
											2008-12-03 09:46:16 -05:00
										 |  |  |             [ ($code-style) ] dip with-nesting | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |         ] with-style | 
					
						
							|  |  |  |     ] ($block) ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $code ( element -- )
 | 
					
						
							|  |  |  |     "\n" join dup <input> [ write ] ($code) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $syntax ( element -- ) "Syntax" $heading $code ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $description ( element -- )
 | 
					
						
							|  |  |  |     "Word description" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $class-description ( element -- )
 | 
					
						
							|  |  |  |     "Class description" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $error-description ( element -- )
 | 
					
						
							|  |  |  |     "Error description" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $var-description ( element -- )
 | 
					
						
							|  |  |  |     "Variable description" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $contract ( element -- )
 | 
					
						
							|  |  |  |     "Generic word contract" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $examples ( element -- )
 | 
					
						
							|  |  |  |     "Examples" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $example ( element -- )
 | 
					
						
							| 
									
										
										
										
											2015-07-19 18:07:02 -04:00
										 |  |  |     unclip-last [ "\n" join ] dip over <input> [ | 
					
						
							| 
									
										
										
										
											2010-02-17 07:18:48 -05:00
										 |  |  |         [ print ] [ output-style get format ] bi*
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] ($code) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $unchecked-example ( element -- )
 | 
					
						
							| 
									
										
										
										
											2015-09-08 19:15:10 -04:00
										 |  |  |     ! help-lint ignores these. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     $example ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $markup-example ( element -- )
 | 
					
						
							|  |  |  |     first dup unparse " print-element" append 1array $code | 
					
						
							|  |  |  |     print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $warning ( element -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         warning-style get [ | 
					
						
							|  |  |  |             last-element off
 | 
					
						
							|  |  |  |             "Warning" $heading print-element | 
					
						
							|  |  |  |         ] with-nesting | 
					
						
							|  |  |  |     ] ($heading) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-20 19:36:55 -04:00
										 |  |  | : $deprecated ( element -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         deprecated-style get [ | 
					
						
							|  |  |  |             last-element off
 | 
					
						
							|  |  |  |             "This word is deprecated" $heading print-element | 
					
						
							|  |  |  |         ] with-nesting | 
					
						
							|  |  |  |     ] ($heading) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 05:53:33 -05:00
										 |  |  | ! Images | 
					
						
							|  |  |  | : $image ( element -- )
 | 
					
						
							| 
									
										
										
										
											2009-04-21 01:27:21 -04:00
										 |  |  |     [ first write-image ] ($span) ;
 | 
					
						
							| 
									
										
										
										
											2009-02-11 05:53:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-24 10:11:45 -04:00
										 |  |  | : <$image> ( path -- element )
 | 
					
						
							|  |  |  |     1array \ $image prefix ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! Some links | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : write-link ( string object -- )
 | 
					
						
							|  |  |  |     link-style get [ write-object ] with-style ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | : link-icon ( topic -- )
 | 
					
						
							|  |  |  |     definition-icon 1array $image ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | : link-text ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2009-02-12 03:09:45 -05:00
										 |  |  |     [ article-name ] keep write-link ;
 | 
					
						
							| 
									
										
										
										
											2009-02-01 07:33:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  | GENERIC: link-long-text ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  | M: topic link-long-text | 
					
						
							|  |  |  |     [ article-title ] keep write-link ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-09 05:46:41 -04:00
										 |  |  | GENERIC: link-effect? ( word -- ? )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: parsing-word link-effect? drop f ;
 | 
					
						
							|  |  |  | M: symbol link-effect? drop f ;
 | 
					
						
							|  |  |  | M: word link-effect? drop t ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $effect ( effect -- )
 | 
					
						
							|  |  |  |     effect>string stack-effect-style get format ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  | M: word link-long-text | 
					
						
							|  |  |  |     dup presented associate [ | 
					
						
							|  |  |  |         [ article-name link-style get format ] | 
					
						
							| 
									
										
										
										
											2009-10-09 05:46:41 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             dup link-effect? [ | 
					
						
							|  |  |  |                 bl stack-effect $effect | 
					
						
							|  |  |  |             ] [ drop ] if
 | 
					
						
							|  |  |  |         ] bi
 | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  |     ] with-nesting ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  | : >topic ( obj -- topic ) dup topic? [ >link ] unless ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-30 14:38:53 -04:00
										 |  |  | : topic-span ( topic quot -- ) [ >topic ] dip ($span) ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  | ERROR: number-of-arguments found required ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-first ( seq -- first )
 | 
					
						
							| 
									
										
										
										
											2015-08-13 19:13:05 -04:00
										 |  |  |     dup length 1 = [ length 1 number-of-arguments ] unless
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |     first-unsafe ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-first2 ( seq -- first second )
 | 
					
						
							| 
									
										
										
										
											2015-08-13 19:13:05 -04:00
										 |  |  |     dup length 2 = [ length 2 number-of-arguments ] unless
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |     first2-unsafe ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-28 08:47:03 -04:00
										 |  |  | PRIVATE>
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-30 14:38:53 -04:00
										 |  |  | : ($link) ( topic -- ) [ link-text ] topic-span ;
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $link ( element -- ) check-first ($link) ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-30 14:38:53 -04:00
										 |  |  | : ($long-link) ( topic -- ) [ link-long-text ] topic-span ;
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $long-link ( element -- ) check-first ($long-link) ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : ($pretty-link) ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2009-09-30 14:38:53 -04:00
										 |  |  |     [ [ link-icon ] [ drop bl ] [ link-text ] tri ] topic-span ;
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $pretty-link ( element -- ) check-first ($pretty-link) ;
 | 
					
						
							| 
									
										
										
										
											2009-02-01 07:33:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | : ($long-pretty-link) ( topic -- )
 | 
					
						
							| 
									
										
										
										
											2009-09-30 14:38:53 -04:00
										 |  |  |     [ [ link-icon ] [ drop bl ] [ link-long-text ] tri ] topic-span ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <$pretty-link> ( definition -- element )
 | 
					
						
							|  |  |  |     1array \ $pretty-link prefix ;
 | 
					
						
							| 
									
										
										
										
											2008-12-20 18:32:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:46:01 -05:00
										 |  |  | : ($subsection) ( element quot -- )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  |         subsection-style get [ call ] with-style | 
					
						
							| 
									
										
										
										
											2008-03-04 23:46:01 -05:00
										 |  |  |     ] ($block) ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | : $subsection* ( topic -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         [ ($long-pretty-link) ] with-scope
 | 
					
						
							|  |  |  |     ] ($subsection) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $subsections ( children -- )
 | 
					
						
							| 
									
										
										
										
											2009-10-04 07:17:54 -04:00
										 |  |  |     [ $subsection* ] each ($blank-line) ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:46:01 -05:00
										 |  |  | : $subsection ( element -- )
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |     check-first $subsection* ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-18 21:27:09 -04:00
										 |  |  | : ($vocab-link) ( text vocab -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-19 15:39:08 -04:00
										 |  |  |     >vocab-link write-link ;
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:46:01 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $vocab-subsection ( element -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |         check-first2 dup vocab-help | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  |         [ 2nip ($long-pretty-link) ] | 
					
						
							|  |  |  |         [ [ >vocab-link link-icon bl ] [ ($vocab-link) ] bi ] | 
					
						
							|  |  |  |         if*
 | 
					
						
							| 
									
										
										
										
											2008-03-04 23:46:01 -05:00
										 |  |  |     ] ($subsection) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 04:45:34 -04:00
										 |  |  | : $vocab-link ( element -- )
 | 
					
						
							| 
									
										
										
										
											2014-11-30 22:26:23 -05:00
										 |  |  |     check-first [ vocab-name ] keep ($vocab-link) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $vocabulary ( element -- )
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |     check-first vocabulary>> [ | 
					
						
							| 
									
										
										
										
											2008-03-05 16:59:15 -05:00
										 |  |  |         "Vocabulary" $heading nl dup ($vocab-link) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     ] when* ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-09 10:44:41 -04:00
										 |  |  | : (textual-list) ( seq quot sep -- )
 | 
					
						
							|  |  |  |     '[ _ print-element ] swap interleave ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : textual-list ( seq quot -- )
 | 
					
						
							| 
									
										
										
										
											2009-09-09 10:44:41 -04:00
										 |  |  |     ", " (textual-list) ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $links ( topics -- )
 | 
					
						
							|  |  |  |     [ [ ($link) ] textual-list ] ($span) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-15 17:17:13 -04:00
										 |  |  | : $vocab-links ( vocabs -- )
 | 
					
						
							| 
									
										
										
										
											2011-10-24 06:37:47 -04:00
										 |  |  |     [ lookup-vocab ] map $links ;
 | 
					
						
							| 
									
										
										
										
											2008-07-15 17:17:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-09 10:44:41 -04:00
										 |  |  | : $breadcrumbs ( topics -- )
 | 
					
						
							|  |  |  |     [ [ ($link) ] " > " (textual-list) ] ($span) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : $see-also ( topics -- )
 | 
					
						
							|  |  |  |     "See also" $heading $links ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-15 17:40:37 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							|  |  |  | :: update-related-words ( words -- affected-words )
 | 
					
						
							|  |  |  |     words words [| affected word | | 
					
						
							|  |  |  |         word "related" [ affected union words ] change-word-prop | 
					
						
							|  |  |  |     ] reduce ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :: clear-unrelated-words ( words affected-words -- )
 | 
					
						
							|  |  |  |     affected-words words diff | 
					
						
							|  |  |  |     [ "related" [ words diff ] change-word-prop ] each ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : notify-related-words ( affected-words -- )
 | 
					
						
							| 
									
										
										
										
											2013-03-10 12:11:18 -04:00
										 |  |  |     fast-set notify-definition-observers ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-15 17:40:37 -04:00
										 |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : related-words ( seq -- )
 | 
					
						
							| 
									
										
										
										
											2011-09-15 17:40:37 -04:00
										 |  |  |     dup update-related-words | 
					
						
							|  |  |  |     [ clear-unrelated-words ] [ notify-related-words ] bi ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $related ( element -- )
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |     check-first dup "related" word-prop remove
 | 
					
						
							| 
									
										
										
										
											2008-09-06 20:13:59 -04:00
										 |  |  |     [ $see-also ] unless-empty ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : ($grid) ( style quot -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         table-content-style get [ | 
					
						
							|  |  |  |             swap [ last-element off call ] tabular-output | 
					
						
							|  |  |  |         ] with-style | 
					
						
							| 
									
										
										
										
											2009-03-11 04:17:30 -04:00
										 |  |  |     ] ($block) ; inline
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $list ( element -- )
 | 
					
						
							|  |  |  |     list-style get [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 bullet get write-cell | 
					
						
							|  |  |  |                 [ print-element ] with-cell | 
					
						
							|  |  |  |             ] with-row | 
					
						
							|  |  |  |         ] each
 | 
					
						
							|  |  |  |     ] ($grid) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $table ( element -- )
 | 
					
						
							|  |  |  |     table-style get [ | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 [ [ print-element ] with-cell ] each
 | 
					
						
							|  |  |  |             ] with-row | 
					
						
							|  |  |  |         ] each
 | 
					
						
							|  |  |  |     ] ($grid) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : a/an ( str -- str )
 | 
					
						
							| 
									
										
										
										
											2008-11-16 07:02:13 -05:00
										 |  |  |     [ first ] [ length ] bi 1 =
 | 
					
						
							|  |  |  |     "afhilmnorsx" "aeiou" ? member? "an" "a" ? ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | GENERIC: ($instance) ( element -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 18:55:18 -04:00
										 |  |  | M: word ($instance) dup name>> a/an write bl ($link) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 18:55:18 -04:00
										 |  |  | M: string ($instance) write ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 13:18:36 -05:00
										 |  |  | M: array ($instance) print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 18:55:18 -04:00
										 |  |  | M: f ($instance) ($link) ;
 | 
					
						
							| 
									
										
										
										
											2008-11-16 07:02:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 11:31:04 -05:00
										 |  |  | : $instance ( element -- ) first ($instance) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-22 20:07:44 -05:00
										 |  |  | : $or ( element -- )
 | 
					
						
							|  |  |  |     dup length { | 
					
						
							|  |  |  |         { 1 [ first ($instance) ] } | 
					
						
							| 
									
										
										
										
											2009-01-22 23:30:43 -05:00
										 |  |  |         { 2 [ first2 [ ($instance) " or " print-element ] [ ($instance) ] bi* ] } | 
					
						
							| 
									
										
										
										
											2009-01-22 20:07:44 -05:00
										 |  |  |         [ | 
					
						
							|  |  |  |             drop
 | 
					
						
							|  |  |  |             unclip-last
 | 
					
						
							|  |  |  |             [ [ ($instance) ", " print-element ] each ] | 
					
						
							|  |  |  |             [ "or " print-element ($instance) ] | 
					
						
							|  |  |  |             bi*
 | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     } case ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 11:31:04 -05:00
										 |  |  | : $maybe ( element -- )
 | 
					
						
							| 
									
										
										
										
											2009-01-22 20:07:44 -05:00
										 |  |  |     f suffix $or ;
 | 
					
						
							| 
									
										
										
										
											2008-11-16 07:02:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 11:31:04 -05:00
										 |  |  | : $quotation ( element -- )
 | 
					
						
							| 
									
										
										
										
											2012-09-27 14:08:52 -04:00
										 |  |  |     check-first | 
					
						
							|  |  |  |     { "a " { $link quotation } " with stack effect " } | 
					
						
							|  |  |  |     print-element $snippet ;
 | 
					
						
							| 
									
										
										
										
											2008-11-16 10:03:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 18:55:18 -04:00
										 |  |  | : ($instances) ( element -- )
 | 
					
						
							|  |  |  |      dup word? [ ($link) "s" print-element ] [ print-element ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $sequence ( element -- )
 | 
					
						
							|  |  |  |     { "a " { $link sequence } " of " } print-element | 
					
						
							|  |  |  |     dup length { | 
					
						
							|  |  |  |         { 1 [ first ($instances) ] } | 
					
						
							|  |  |  |         { 2 [ first2 [ ($instances) " or " print-element ] [ ($instances) ] bi* ] } | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             drop
 | 
					
						
							|  |  |  |             unclip-last
 | 
					
						
							|  |  |  |             [ [ ($instances) ", " print-element ] each ] | 
					
						
							|  |  |  |             [ "or " print-element ($instances) ] | 
					
						
							|  |  |  |             bi*
 | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     } case ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : values-row ( seq -- seq )
 | 
					
						
							| 
									
										
										
										
											2009-03-22 18:53:06 -04:00
										 |  |  |     unclip \ $snippet swap present 2array
 | 
					
						
							| 
									
										
										
										
											2008-03-31 20:18:05 -04:00
										 |  |  |     swap dup first word? [ \ $instance prefix ] when 2array ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $values ( element -- )
 | 
					
						
							|  |  |  |     "Inputs and outputs" $heading | 
					
						
							|  |  |  |     [ values-row ] map $table ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $side-effects ( element -- )
 | 
					
						
							|  |  |  |     "Side effects" $heading "Modifies " print-element | 
					
						
							|  |  |  |     [ $snippet ] textual-list ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $errors ( element -- )
 | 
					
						
							|  |  |  |     "Errors" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $notes ( element -- )
 | 
					
						
							|  |  |  |     "Notes" $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-23 21:24:54 -04:00
										 |  |  | : ($see) ( word quot -- )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2009-09-08 12:43:47 -04:00
										 |  |  |         code-char-style get [ | 
					
						
							| 
									
										
										
										
											2008-08-23 21:24:54 -04:00
										 |  |  |             code-style get swap with-nesting | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |         ] with-style | 
					
						
							| 
									
										
										
										
											2008-08-23 21:24:54 -04:00
										 |  |  |     ] ($block) ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  | : $see ( element -- ) check-first [ see* ] ($see) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  | : $synopsis ( element -- ) check-first [ synopsis write ] ($see) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $definition ( element -- )
 | 
					
						
							|  |  |  |     "Definition" $heading $see ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-22 04:37:46 -05:00
										 |  |  | : $methods ( element -- )
 | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |     check-first methods [ | 
					
						
							| 
									
										
										
										
											2008-11-29 00:24:59 -05:00
										 |  |  |         "Methods" $heading | 
					
						
							|  |  |  |         [ see-all ] ($see) | 
					
						
							|  |  |  |     ] unless-empty ;
 | 
					
						
							| 
									
										
										
										
											2008-11-22 04:37:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : $value ( object -- )
 | 
					
						
							|  |  |  |     "Variable value" $heading | 
					
						
							|  |  |  |     "Current value in global namespace:" print-element | 
					
						
							| 
									
										
										
										
											2012-07-22 17:05:30 -04:00
										 |  |  |     check-first dup [ pprint-short ] ($code) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $curious ( element -- )
 | 
					
						
							|  |  |  |     "For the curious..." $heading print-element ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $references ( element -- )
 | 
					
						
							|  |  |  |     "References" $heading | 
					
						
							|  |  |  |     unclip print-element [ \ $link swap ] { } map>assoc $list ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $shuffle ( element -- )
 | 
					
						
							|  |  |  |     drop
 | 
					
						
							| 
									
										
										
										
											2009-10-29 20:34:25 -04:00
										 |  |  |     "Shuffle word. Rearranges the top of the datastack as indicated in the stack effect pattern." $description ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : $complex-shuffle ( element -- )
 | 
					
						
							| 
									
										
										
										
											2019-07-23 21:10:19 -04:00
										 |  |  |     $shuffle | 
					
						
							| 
									
										
										
										
											2009-10-29 20:34:25 -04:00
										 |  |  |     { "The data flow represented by this shuffle word can be more clearly expressed using " { $link "locals" } "." } $deprecated ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $low-level-note ( children -- )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     drop
 | 
					
						
							|  |  |  |     "Calling this word directly is not necessary in most cases. Higher-level words call it automatically." $notes ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $values-x/y ( children -- )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     drop { { "x" number } { "y" number } } $values ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-25 04:53:36 -04:00
										 |  |  | : $parsing-note ( children -- )
 | 
					
						
							|  |  |  |     drop
 | 
					
						
							|  |  |  |     "This word should only be called from parsing words." | 
					
						
							|  |  |  |     $notes ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $io-error ( children -- )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     drop
 | 
					
						
							|  |  |  |     "Throws an error if the I/O operation fails." $errors ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 16:32:55 -04:00
										 |  |  | : $prettyprinting-note ( children -- )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     drop { | 
					
						
							|  |  |  |         "This word should only be called from inside the " | 
					
						
							|  |  |  |         { $link with-pprint } " combinator." | 
					
						
							|  |  |  |     } $notes ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-19 10:54:24 -04:00
										 |  |  | : $content ( element -- )
 | 
					
						
							|  |  |  |     first article-content print-content nl ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | GENERIC: elements* ( elt-type element -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-20 18:32:38 -05:00
										 |  |  | M: simple-element elements* | 
					
						
							|  |  |  |     [ elements* ] with each ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: object elements* 2drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: array elements* | 
					
						
							| 
									
										
										
										
											2009-10-23 04:27:45 -04:00
										 |  |  |     [ dup first \ $markup-example eq? [ 2drop ] [ [ elements* ] with each ] if ] | 
					
						
							|  |  |  |     [ [ first eq? ] keep swap [ , ] [ drop ] if ] 2bi ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : elements ( elt-type element -- seq ) [ elements* ] { } make ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : collect-elements ( element seq -- elements )
 | 
					
						
							| 
									
										
										
										
											2019-09-11 07:59:56 -04:00
										 |  |  |     swap '[ [ _ elements* ] each ] { } make [ rest ] map concat ;
 | 
					
						
							| 
									
										
										
										
											2008-11-22 04:22:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <$link> ( topic -- element )
 | 
					
						
							| 
									
										
										
										
											2008-12-11 17:47:38 -05:00
										 |  |  |     1array \ $link prefix ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <$snippet> ( str -- element )
 | 
					
						
							|  |  |  |     1array \ $snippet prefix ;
 | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : $definition-icons ( element -- )
 | 
					
						
							|  |  |  |     drop
 | 
					
						
							| 
									
										
										
										
											2011-04-07 12:01:21 -04:00
										 |  |  |     icons get sort-keys | 
					
						
							| 
									
										
										
										
											2009-09-21 15:35:16 -04:00
										 |  |  |     [ [ <$link> ] [ definition-icon-path <$image> ] bi* swap ] assoc-map
 | 
					
						
							| 
									
										
										
										
											2020-02-13 18:20:17 -05:00
										 |  |  |     { f { $strong "Definition class" } } prefix
 | 
					
						
							| 
									
										
										
										
											2009-10-29 20:34:25 -04:00
										 |  |  |     $table ;
 |