Talk:Range extraction: Difference between revisions

Content added Content deleted
(On Algol and duck typing.)
Line 6: Line 6:
Hi Neville, I noted this comment from your Algol solution:
Hi Neville, I noted this comment from your Algol solution:
:''Note: The closest concept that Algol 68 has to duck typing is the tagged union. If duck typing was available it could reduced the size of the code specimen, but would have lost some of Algol 68's strong type data security. ''
:''Note: The closest concept that Algol 68 has to duck typing is the tagged union. If duck typing was available it could reduced the size of the code specimen, but would have lost some of Algol 68's strong type data security. ''
Thinking about it, you could form and use a list of ranges for what is to become each entry in the 'rangified' internal format, where each entry range is a pair of integers. It would then only be converted to the dash separated integer range form, or two comma separated digits, or one digit, in the routine to create a correctly formed string depending if the second number minus the first number in the range is: >= 2, or ==1, or == 0. --[[User:Paddy3118|Paddy3118]] 05:24, 16 July 2010 (UTC)
Thinking about it, you could form and use a list of ranges for what is to become each entry in the 'rangified' internal format, where each entry range is a pair of integers. It would then only be converted to the dash separated integer range form, or two comma separated digits, or one digit, in the routine to create a correctly formed string depending if the second number minus the first number in the range is: >= 2, or ==1, or == 0.

--[[User:Paddy3118|Paddy3118]] 05:24, 16 July 2010 (UTC)

I see that you are saying. Essentially the middle iterator ''gen range merge'' is actually doing this that you describe.
I inserted ''gen range merge'' in the middle of a chain of iterators. These chained iterators do the following steps:
# Iterate through three different types of initial arrays - []'''int''', []'''range''' and []'''rangeint''' with ''gen range'', yielding '''range'''(''lwb'',''upb'')
# Iterate with ''gen range merge'' yielding <u>merged</u> '''range'''(''lwb'',''upb'')
# Iterate with ''gen range int merge'', merging and yielding a '''union''' of '''int''' and '''range'''
# Finally iterate with ''range int list init'' '''exiting''' with an array of '''union''' of '''int''' and '''range'''.

I could have just restricted the code to the behaviour of ''gen range merge'' with 'rangified' internal format, but I having used python heaps and I am endeared to the flexibility that duck typing and iterators provide to python. In this instance I am glad to be able to mimic some of the ''duck typing'' flexibility and use iterators in the much older Algol 68.

Moreover this code specimen also produces the nice "bi-product" of a family of '''range''' helper functions, and a non-trivial example of iterating in Algol 68.

[[User:NevilleDNZ|NevilleDNZ]] 07:02, 16 July 2010 (UTC)