ycl

Artifact [414e3f8f7f]
Login

Artifact [414e3f8f7f]

Artifact 414e3f8f7fd5452cbecbf2502a3d1bd520c1e6be:


#! /usr/bin/env tclsh

namespace eval env {
	package require {ycl proc}
	[yclprefix] proc alias [yclprefix]::proc::alias
	alias aliases [yclprefix] proc aliases
}
namespace path env


aliases {
	{ycl eval} {
		eset
	}
	{ycl ns join}
}


variable doc::count {
	description

		counts the segments in a value 

	args


		target

			the value to bisect

		operator

			a command prefix

				description

					returns the size of a number of units

				args

					number

						a number of units 
}
proc count {target multiplier} {
	set used 0
	set count 0
	while 1 {
		set pow 0
		set candidate 0
		while 1 {
			set newcandidate [expr {$candidate + (2 ** $pow)}]
			set newtotal [expr {$used + [{*}$multiplier $newcandidate]}]
			if {$newtotal > $target} break
			set used $newtotal
			incr count $newcandidate
			incr pow
		}
		if {$pow == 0} {
			break
		}
	}
	list $count $used
}



proc expr args {
	switch [llength $args] {
		1 {
			set varname expr
		} default {
			set args [lassign $args[set args {}] varname]
		}
	}
	tailcall eset $varname ::expr {*}$args
}


proc max varname {
	upvar 1 $varname var
	eset var max_ {*}$var
}


alias max_ [join {} tcl mathfunc max]