https://github.com/jrincayc/ucblogo-code
Revision ad2aafdb76721bf7ee061407f6a92e005841f163 authored by Joshua Cogliati on 28 June 2022, 01:19:29 UTC, committed by GitHub on 28 June 2022, 01:19:29 UTC
ISSUE-134: Fixed issue with LOADPICT if it's called before other turtle commands
2 parent s 7301609 + 3504376
Raw File
Tip revision: ad2aafdb76721bf7ee061407f6a92e005841f163 authored by Joshua Cogliati on 28 June 2022, 01:19:29 UTC
Merge pull request #135 from dmalec/ISSUE-134
Tip revision: ad2aafd
reduce
REDUCE template data					(library procedure)

	outputs the result of applying the template to accumulate the
	members of the data input.  The template must be a two-slot
	function.  Typically it is an associative function name like SUM.
	If the data input has only one constituent (member in a list or
	character in a word), the output is that consituent.  Otherwise,
	the template is first applied with ?1 filled with the next-to-last
	consitient and ?2 with the last constituent.  Then, if there are
	more constituents, the template is applied with ?1 filled with the
	next constituent to the left and ?2 with the result from the
	previous evaluation.  This process continues until all constituents
	have been used.  The data input may not be empty.

	Note: If the template is, like SUM, the name of a procedure that is
	capable of accepting arbitrarily many inputs, it is more efficient
	to use APPLY instead of REDUCE.  The latter is good for associative
	procedures that have been written to accept exactly two inputs:

		to max :a :b
		output ifelse :a > :b [:a] [:b]
		end

		print reduce "max [...]

	Alternatively, REDUCE can be used to write MAX as a procedure
	that accepts any number of inputs, as SUM does:

		to max [:inputs] 2
		if emptyp :inputs ~
		   [(throw "error [not enough inputs to max])]
		output reduce [ifelse ?1 > ?2 [?1] [?2]] :inputs
		end

back to top