Plan 9 from Bell Labs’s /usr/web/sources/contrib/akumar/cmd/math/comp

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

rfork en

fn usage {
	echo usage: $0 '[-x var] [-i ''[min [inc]] max]''] [file] expr'
	exit usage
}

bnds=()

while(~ $1 -*){
	switch($1){
	case -x
		var=$2
		shift
	case -i
		l=`{ echo $2}
		for(i in $l)
			bnds=($i $bnds)
		l=()
		shift
	case -*
		usage
	}
	shift
}

if(! ~ $#* 1 2)
	usage

if(~ $#* 2){
	funcs=$1
	shift
}

if(~ $var '')
	var=α

fn holoop {
	switch($#bnds){
	case 0
		bnds=(4 1 0)
	case 1
		bnds=($bnds 1 0)
	case 2
		bnds=($bnds(1) 1 $bnds(2))
	}

	echo -n 'for(i='$bnds(3)'; i<'$bnds(1)'; i+='$bnds(2)')'
	echo -n '{
		print i
		print '
	read -n 1
	echo '
		print "\n"
	}'
}

fn hocomp {
	if(! ~ $funcs '')
		cat $funcs || exit error
	holoop
}

echo $1 | sed 's/'^$var^'/i/g' | hocomp | hoc | gview

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].