How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Forum for discussion about the documentation project.
Lost Zergling
Posts: 154
Joined: Dec 02, 2011 22:51
Location: France

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby Lost Zergling » Sep 28, 2018 16:43

Offtopic. What annoys me a bit is not so much to notice a certain loss of FB audience over time, it is also a bit of the loss of exuberance and vitality of that a few years. I feel badly placed to criticize the "school book" side, especially on a post dedicated to documentation. Modern times. It's just that it makes me nostalgic: I can not even rememore the no of this cabbage leaf that published various source codes, varied and often buggy for the family computers of the 80s. bugs and funny drawings, far from Inria computer courses. The breath of the pioneers has become, but what remains for us? I mean the spirit. How to defend it, to talk about it, to transmit it? Give me the desire, .. Let's rock! I am here the devil's advocate, but without the devil, is there anything else but the machine and its perfect equation: the ultimate solution to the problem of knowledge. Near future. And if in fact, it's the soul that was the devil?
dodicat
Posts: 5332
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby dodicat » Sep 28, 2018 21:33

Thanks Lost Zerling.
I don't believe that you are lost. I think you are actually AWOL.
You should make your way back to rejoin your comrades with that renewed fighting spirit.
Lost Zergling
Posts: 154
Joined: Dec 02, 2011 22:51
Location: France

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby Lost Zergling » Sep 28, 2018 22:24

"Give me the desire" is a reference to a famous song of a famous French rocker, sorry if you miss it : heard desire for coding/learning. "anything else but the machine and its perfect equation: the ultimate solution to the problem of knowledge" : I was thinking about automatic formatting of teaching. The message I tried to understand was almost about the importance of human aspect in the transmission of knowledge : I do not regret the programming of 30 years ago, but the pioneering spirit that was that of the Basic. Missunderstandings I think, I should have explain my thought more clearly than smoking parabols. It does not bother me to be Awol, but till my presence becomes undesirable maybe one day I'll meet other Awol people or I'll be lost.
badidea
Posts: 1054
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby badidea » Nov 17, 2018 23:17

fxm wrote:No problem. Everyone has the right to be inspired by code on the forum (like my first version of user stack) and modify it as it sees fit.

Myself, I yesterday modified it, but just to gain speed of execution!
(important when we want to replace the execution stack by its own stack)

I believe you posted this in a different topic, but I really cannot find it.
Anyway, my question is. Is it possible to use lists of different types of variables (in one project) with only one list class definition without using macros? Or does this requires the C++ template thing? Reason: I don't like macros.
sancho3
Posts: 313
Joined: Sep 30, 2017 3:22

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby sancho3 » Nov 18, 2018 9:31

@badidea:
That is called generics. This is a current wishlist item for fb.
The answer is no you can't, without jumping through some ugly hoops.
You can try to build your list with any pointers but then you will either fill your comparison method code full of if/else (if myobject is string elseif myobject is integer etc) and even then that still limits it to built in data types.
And since typeof() is a compiler intrinsic you can't use it to directly tell what kind of variables you are comparing. This means that you are going to need some kind of flag to tell your list how to compare two items (when adding to it or searching in it).
So then you can try to put your comparison operation code outside of the list object (using function pointers) but then you will find that that method is just taking those if/else statements out of the list object and moving them into the general logic of the program.
So you are either going to have to limit the type of variables your list can store or use the macro system.
imo
badidea
Posts: 1054
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby badidea » Nov 18, 2018 10:19

I tried something with define and namespace. This way a least only one file for the class:

Code: Select all

namespace DLINT
   #define data_type integer
   #include "dyn_list_v02.bi"
   #undef data_type
end namespace

namespace DLSGL
   #define data_type single
   #include "dyn_list_v02.bi"
   #undef data_type
end namespace

dim as DLINT.list_type list1
list1.push(1)

dim as DLSGL.list_type list2
list2.push(1.0)

Where dyn_list_v02.bi is:

Code: Select all

type list_type
   public:
   declare property push(byval value as data_type)
   declare property pop() as data_type
   declare property size() as integer 'stack size
   declare property find(byval value as data_type) as integer
   declare property get(index as integer) as data_type
   declare destructor()
   private:
   dim as data_type list(any) 'stack
   dim as integer current = 0
end type

'increase list size + add value
property list_type.push(byval value as data_type)
   redim preserve list(ubound(list) + 1)
   list(ubound(list)) = value
end property

property list_type.pop() as data_type
   dim as data_type value
   select case ubound(list)
   case is > 0
      'get value + decrease list size
      value = list(ubound(list))
      redim preserve list(ubound(list) - 1)
   case is = 0
      'get value + empty list
      value = list(ubound(list))
      erase list
   case else
      'keep uninitialised value
   end select
   return value
end property

property list_type.size() as integer
   return ubound(list) + 1
end property

'find first match
property list_type.find(byval value as data_type) as integer
   for i as integer = lbound(list) to ubound(list)
      if list(i) = value then return i
   next
   return -1
end property

property list_type.get(index as integer) as data_type
   dim as data_type value
   if index >= lbound(list) and index <= ubound(list) then
      value = list(index)
   end if
   return value
end property

destructor list_type
   erase list
end destructor
badidea
Posts: 1054
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby badidea » Nov 18, 2018 17:25

A list of lists. Only the = operator needs to be implemented for the find method to work (in above dyn_list_v02.bi):
Edit: This list of lists needs rethinking.

Code: Select all

namespace DL_INT
   #define data_type integer
   #include "dyn_list_v02.bi"
   #undef data_type
end namespace

namespace DL_INT_LIST
   #define data_type DL_INT.list_type
   #include "dyn_list_v02.bi"
   #undef data_type
end namespace

dim as DL_INT.list_type intList1, intList2
intList1.push(11) : intList1.push(12) : intList1.push(13)
intList2.push(21) : intList2.push(22) : intList2.push(23)

dim as DL_INT_LIST.list_type intListList
intListList.push(intList1)
intListList.push(intList2)
Last edited by badidea on Nov 18, 2018 22:59, edited 1 time in total.
sancho3
Posts: 313
Joined: Sep 30, 2017 3:22

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby sancho3 » Nov 18, 2018 19:47

That is the macro method of implementing generic-like types.
#define defines a macro.
Instead of wrapping the type directly inside a macro you have the namespace. But for sure without the #define (macro) you can't isolate the type.
Still the problem similar to a host of if/else. You now have a host of namespaces.
Its an approach I haven't seen before though and interesting.
badidea
Posts: 1054
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: How to Replace Any Recursion with Simple Iteration or Unlimited Iteration with its Own Stack, in FB

Postby badidea » Nov 18, 2018 21:17

The compiler error reporting seems to work better this way. The compiler now shows the line where the bug is (in the class implementation).
It the first time that I use the namespace keyword, so there might be issues I am unaware of.

Edit: There might be a problem with the list of list (previous post). How to get an arbitrary number integer lists (that is part of the lists of lists).

Return to “Documentation”

Who is online

Users browsing this forum: No registered users and 1 guest