Does this range reference anomaly occur in Lion & ML too?

Hi.

I’m currently rewriting my “unScripted” article about range references to bring it up to date and hopefully to make it bit more readable! :rolleyes:

While testing some scripts for it, I’ve come across an anomaly in Snow Leopard which doesn’t occur in Leopard or Tiger and which I’m pretty sure didn’t on my old Jaguar system either.

It happens when a ‘middle’ reference form is used as a boundary specifier in a range reference involving text. The expected result is that the returned extract(s) will begin or end with the middle element specified as the boundary. But in Snow Leopard, it begins or ends with the middle element of the type to be returned:

set myText to "Dip dip dip
My little ship
Sails on the water
Like a cup and saucer
The one who comes to number eight is it"

middle word of myText --> "a" (Just so that we know!)

-- Range reference with 'middle' boundary:
paragraphs from middle word to end of myText

-- Expected result as in Tiger and Leopard. Begins with the middle word.
--> {"a cup and saucer", "The one who comes to number eight is it"}

-- Result in Snow Leopard. Begins with the middle paragraph instead!
--> {"Sails on the water", "Like a cup and saucer", "The one who comes to number eight is it"}

On all three of the systems available to me, using ‘middle’ in a range reference involving a list results in a “Can’t get .” error, so ‘middle’ is probably best avoided altogether in range references. But I’d be interested to know what the situation is in Lion and Mountain Lion. Would any users of those systems be kind enough to tell me what the above script returns on their machines? Thanks. :slight_smile:

Hello Nigel,

in Lion the result is the same as in Snow Leopard

It’s interesting that these two syntax forms


text middle word thru end of myText
text from middle word to end of myText

both result
cup and saucer
The one who comes to number eight is it

Hi, Stefan. Thanks!

Yes. In this case, the initial “c” in the result is the middle character of myText.

Mountain Lion is the same as Lion and Snow Leopard.

Thanks, Shane. That brings me up to date. The change has probably gone unnoticed this long because no-one else has needed to write such a stupid script. :wink:

According to the overview of the release notes of AppleScript and it’s OS they have changed the way unicode text is counted (10.6 section). I think this ‘new’ way of counting has affected the way middle works as well.

Glad to hear a great article getting updated.

The middle is not something used very often. Here is however a plausible usage, ( I think :slight_smile: )


to getMedian for aNumberList
	set b to count aNumberList
	if b mod 2 = 0 then
		set b to b div 2
		set a to ((number b of aNumberList) + (number (b + 1) of aNumberList)) / 2
	else
		set a to middle number of aNumberList
	end if
end getMedian

middle = x div 2 + x mod 2

Another case when you need such things is when you have ordered list and have an non-indexed lookup function. Then you can bring down the iterations to 25% of the length of the data instead of the standard 50%.

Hello! :slight_smile:

I can’t see what you mean, could you provide a small sketch? :slight_smile:

Thanks for putting the Releasenotes on the table, the word boundary problem, has bugged me for a long while, (that dashes is considered word breaking and such.

Reading the Releasenotes, I realize I can detail control what is a word character, and what not to a much greater extent. (From SL onwards)

Or it’s a bug that crept in at the time the other changes were made. I can’t see how the change to underlying definitions of words matters here, given that it seems to be ignored.

Or more economically: (x + 1) div 2.

I’m not sure what you mean here. If you’re talking about a binary search, ‘middle’ isn’t suitable for that. In fact I can’t see much use for it at all, except to introduce a little “Englishlikeness” (!) where it works.

So, if this is, as Shane suggests, a bug they didn’t fix, then it isn’t hard to understand that they didn’t prioritize it.

And it may be useless, but it adds to the charm! :slight_smile:

Here is a little dice game called 421, as uselsess as middle, which could be regarded as a bug in itself, and removed, as it lacks any purpose! (IMHO) (But still charming :D)


set aDice to {1, 2, 3, 4, 5, 6}
repeat
	set a to {}
	repeat with d from 1 to 3
		set end of a to some number in aDice
	end repeat
	set won to false
	repeat with i from 1 to 3
		if first number of a is equal to middle number of a and middle number of a is equal to last number of a then
			win(a)
			set won to true
			exit repeat
			
		else if first number of a is equal to middle number of a then
			if (first number of a) + (middle number of a) is 2 then
				win(a)
				set won to true
				exit repeat
				
			else if i < 3 then
				set last item of a to some number in aDice
			end if
			
		else if first number of a is equal to last number of a then
			if (first number of a) + (last number of a) is 2 then
				win(a)
				set won to true
				exit repeat
			else if i < 3 then
				set middle item of a to some number in aDice
			end if
			
		else if middle number of a is equal to last number of a then
			if (middle number of a) + (last number of a) is 2 then
				win(a)
				set won to true
				exit repeat
			else if i < 3 then
				set middle item of a to some number in aDice
			end if
			
		else if 4 is in a and 2 is in a and 1 is in a then
			win(a)
			set won to true
			exit repeat
		else if 1 is in a and i < 3 then
			if 1 is item 1 of a then
				set middle item of a to some number of aDice
				set last item of a to some number of aDice
			else if 1 is middle item of a then
				set first item of a to some number of aDice
				set last item of a to some number of aDice
			else
				set first item of a to some number of aDice
				set middle item of a to some number of aDice
			end if
		else if i < 3 then
			set first item of a to some number of aDice
			set middle item of a to some number of aDice
			set last item of a to some number of aDice
			
		end if
	end repeat
	
	if not won then
		tell application "SystemUIServer"
			activate
			display dialog "You lost!
		" & first item of a & " " & middle item of a & " " & last item of a with title " 4 2 1 "
		end tell
	end if
end repeat

to win(a)
	set b to {}
	if first item of a ≥ middle item of a and first item of a ≥ last item of a then
		set end of b to first item of a
		set a to rest of a
	else if middle item of a ≥ first item of a and middle item of a ≥ last item of a then
		set end of b to middle item of a
		set a to first item of a & last item of a
	else
		set end of b to last item of a
		set a to first item of a & middle item of a
	end if
	if last item of a is 2 then
		set b to b & reverse of a
	else
		set b to b & a
	end if
	tell application "SystemUIServer"
		activate
		display dialog "You won!
		" & first item of b & " " & middle item of b & " " & last item of b with title " 4 2 1 "
	end tell
end win

This is of course related to “English likeness” :smiley:


(*
$NetBSD: acronyms,v 1.112 2002/09/27 03:40:46 junyoung Exp $
*)

set acronyms to "AFAIC	as far as I'm concerned
AFAICR	as far as I can recall
AFAICT	as far as I can tell
AFAIK	as far as I know
AFAIR	as far as I recall
AFAIU	as far as I understand
AFD	away from desktop
AFK	away from keyboard
AFU	all fucked up
AFW	away from window
AIU	as I understand
AIUI	as I understand it
AKA	also known as
ASAIC	as soon as I can
ASAP	as soon as possible
ATM	at the moment
AWOL	absent without official leave
AYBABTU	all your base are belong to us
B/C	because
B/S	bullshit
B/W	between
BBIAB	be back in a bit
BBL	[I'll] be back later
BBS	be back soon
BBT	be back tomorrow
BFD	big fucking deal
BIAB	back in a bit
BIAF	back in a few
BIALW	back in a little while
BIAS	back in a second
BIAW	back in a while
BOATILAS	bend over and take it like a slut
BOFH	bastard operator from hell
BOGAHICA	bend over, grab ankles, here it comes again
BOHICA	bend over here it comes again
BRB	[I'll] be right back
BS	bullshit
BTDT	been there, done that
BTTH	boot to the head
BTW	by the way
CMIIW	correct me if I'm wrong
CNP	continued [in my] next post
COB	close of business [day]
COTS	commercial off-the-shelf
CYA	see you around
D/L	download
DIY	do it yourself
DKDC	don't know, don't care
DSTM	don't shoot the messenger
DTRT	do the right thing
DTWT	do the wrong thing
DWIM	do what I mean
EG	evil grin
EMSG	email message
EOB	end of business [day]
EOD	end of discussion
EOL	end of life
ETLA	extended three letter acronym
EWAG	experienced wild-ass guess
FAQ	frequently asked question
FCFS	first come first served
FIGJAM	fuck I'm good, just ask me
FIIK	fuck[ed] if I know
FIIR	fuck[ed] if I remember
FINK	Fink is not an acronym. See http://fink.sourceforge.net/faq/general.php#naming
FM	fucking magic
FOAD	fall over and die
FSDO	for some definition of
FSVO	for some value of
FTFM	fuck the fuckin' manual!
FUBAR	fucked up beyond all recognition
FUD	fear, uncertainty and doubt
FWIW	for what it's worth
FYI	for your information
G	grin
G/C	garbage collect
GAC	get a clue
GAL	get a life
GIGO	garbage in, garbage out
GMTA	great minds think alike
GTFO	get the fuck out
GTG	got to go
HAND	have a nice day
HHIS	hanging head in shame
HICA	here it comes again
HTH	hope this helps
IAC	in any case
IANAL	I am not a lawyer
IC	I see
ICBW	I could be wrong
ICCL	I couldn't care less
IHAFC	I haven't a fucking clue
IHBW	I have been wrong
IHNFC	I have no fucking clue
IIANM	if I am not mistaken
IIRC	if I recall correctly
IIUC	if I understand correctly
IMAO	in my arrogant opinion
IMCO	in my considered opinion
IMHO	in my humble opinion
IMNSHO	in my not so humble opinion
IMO	in my opinion
IOW	in other words
IRL	in real life
ISAGN	I see a great need
ISTM	it seems to me
ISTR	I seem to recall
ITYM	I think you mean
IWBNI	it would be nice if
IYSS	If you say so
IYSS	if you say so
J/K	just kidding
JHD	just hit ``delete''
JIC	just in case
JK	just kidding
JMO	just my opinion
JTLYK	just to let you know
KISS	keep it simple, stupid
KITA	kick in the ass
KNF	kernel normal form
L8R	later
LART	luser attitude readjustment tool (ie, hammer)
LJBF	let's just be friends
LMAO	laughing my ass off
LMSO	laughing my socks off
LOL	laughing out loud
LTNS	long time no see
MIA	missing in action
MMU	memory management unit
MOTAS	member of the appropriate sex
MOTOS	member of the opposite sex
MOTSS	member of the same sex
MTF	more to follow
MYOB	mind your own business
N/M	never mind
NBD	no big deal
NFC	no fucking clue
NFI	no fucking idea
NFW	no fucking way
NIH	not invented here
NMF	not my fault
NMP	not my problem
NOYB	none of your business
NOYFB	none of your fucking business
NP	no problem
NRFPT	not ready for prime time
NRN	no reply necessary
OIC	oh, I see
OMG	oh, my god
OT	off topic
OTL	out to lunch
OTOH	on the other hand
OTT	over the top
OTTOMH	off the top of my head
PEBKAC	problem exists between keyboard and chair
PFO	please fuck off
PFY	pimply faced youth
PITA	pain in the ass
PKSP	pound keys and spew profanity
PNG	persona non grata
PNP	plug and pray
POC	point of contact
POLA	principle of least astonishment
POS	piece of shit
PPL	pretty please
PTV	parental tunnel vision
QED	quod erat demonstrandum
RFC	request for comments
RIP	rest in peace
RL	real life
RLC	rod length check
ROFL	rolling on floor laughing
ROFLMAO	rolling on floor laughing my ass off
ROTFL	rolling on the floor laughing
RP	responsible person
RSN	real soon now
RTFB	read the fine/fucking book
RTFC	read the fine/fucking code
RTFD	read the fine/fucking documentation
RTFM	read the fine/fucking manual
RTFMP	read the fine/fucking man page
RTFS	read the fine/fucking source
SCNR	sorry, could not resist
SEP	someone else's problem
SFA	sweet fuck all
SHID	slaps head in disgust
SIMCA	sitting in my chair amused
SMLSFB	so many losers, so few bullets
SMOP	simple matter of programming
SNAFU	situation normal, all fucked up
SNERT	snot-nosed egotistical rude teenager
SNMP	sorry, not my problem
SNR	signal to noise ratio
SO	significant other
SOB	son of [a] bitch
SOL	shit out [of] luck
SOP	standard operating procedure
SSIA	subject says it all
STFA	search the fucking archives
STFU	shut the fuck up
SUS	stupid user syndrome
SWAG	silly, wild-assed guess
SWAHBI	silly, wild-assed hare-brained idea
SWMBO	she who must be obeyed
TANSTAAFL	there ain't no such thing as a free lunch
TBC	to be continued
TBD	to be {decided,determined,done}
TBOMK	the best of my knowledge
THNX	thanks
THX	thanks
TIA	thanks in advance
TINC	there is no cabal
TLA	three letter acronym
TLB	translation lookaside buffer
TMA	too many abbreviations
TMI	too much information
TOEFL	test of english as a foreign language
TPTB	the powers that be
TRT	the right thing
TTBOMK	to the best of my knowledge
TTFN	ta ta for now
TTYL	talk to you later
TWIAVBP	the world is a very big place
TY	thank you
TYVM	thank you very much
U/L	upload
UTSL	use the source, Luke
VEG	very evil grin
W/	with
W/O	without
WAG	wild-ass guess
WB	welcome back
WFM	works for me
WIBNI	wouldn't it be nice if
WIP	work in progress
WOFTAM	waste of fucking time and money
WOMBAT	waste of money, brain, and time
WRT	with respect to
WTF	{what,where,who,why} the fuck
WTH	{what,where,who,why} the hell
WYSIWYG	what you see is what you get
YALIMO	you are lame, in my opinion
YHBT	you have been trolled
YHL	you have lost
YKWIM	you know what I mean
YMA	yo momma's ass
YMMV	your mileage may vary
YW	 you're welcome"
repeat
	tell application "SystemUIServer"
		activate
		set mp to some paragraph of acronyms
		display dialog mp
	end tell
end repeat