Page 1 of 1

Pointers, arrays and dynamic lists on Rexx

PostPosted: Fri May 28, 2010 3:32 am
by hakghen
Greetings fellow friends!

I need to present on my university a little teamwork with example of some languages using pointers, arrays and dynamic lists (for those who don't know, a kind of array that, instead of allocation a fixed ammount of memory to be used, uses the free memory to "keep" the variables' values and addresses of the next array element in memory).

People in my group are using Pascal, C, Java and etc, I, as a mainframe student, would like to use REXX, if possible (I thought of COBOL, but using pointers in COBOL, IMO is just some kind of plain madness).

But, I couldn't find anything solid to base my studies upon to create these examples. We have an exercise list with problems that we must solve with the selected languages.

Could any of you help me? Examples or even some documentation regarding the use of pointers on REXX would be very much appreciated!

Re: Pointers, arrays and dynamic lists on Rexx

PostPosted: Sat May 29, 2010 3:34 pm
by expat
Click HERE to access all of the manuals that you will require to do this is REXX. Look particularly at STEM variables.

Re: Pointers, arrays and dynamic lists on Rexx

PostPosted: Sat May 29, 2010 11:57 pm
by prino
/* REXX exec to demonstrate pseudo list processing                    */
/*** trace ?r ***************************************************** \| *
*               (C) Copyright Robert AH Prins, 1994-1994               *
************************************************************************
*  ------------------------------------------------------------------  *
* | Date       | By   | Remarks                                      | *
* |------------+------+----------------------------------------------| *
* |            |      |                                              | *
* |------------+------+----------------------------------------------| *
* | 1994-10-18 | RAHP | Initial version                              | *
* |------------+------+----------------------------------------------| *
************************************************************************
* LISTPROC is an exec to provide an example of how to emulate PL/I     *
* list processing in REXX.                                             *
***********************************************************************/
my_list. = 0
my_top   = 0
my_end   = 0
prv_ptr  = 0
!my_ptr  = 0

/***********************************************************************
* "Allocate" a list                                                    *
***********************************************************************/
do i = 1 to 10
  !my_ptr = !my_ptr + 1
  my_list.!my_ptr.data = substr('ABCDEFGHIJ', i, 1)

  if my_top = 0 then
    my_top = !my_ptr
  else
    my_list.my_end.my_nxt = !my_ptr

  my_list.!my_ptr.my_prv = prv_ptr
  my_end                 = !my_ptr
  prv_ptr                = !my_ptr
end

/***********************************************************************
* Print the list in forward direction                                  *
***********************************************************************/
!my_ptr = my_top
do while !my_ptr \= 0
  say '-> Item' !my_ptr 'Contents' my_list.!my_ptr.data
  !my_ptr = my_list.!my_ptr.my_nxt
end

/***********************************************************************
* Print the list in backward direction                                 *
***********************************************************************/
!my_ptr = my_end
do while !my_ptr \= 0
  say '<- Item' !my_ptr 'Contents' my_list.!my_ptr.data
  !my_ptr = my_list.!my_ptr.my_prv
end

/***********************************************************************
* "Free" the list                                                      *
***********************************************************************/
drop my_list.
my_list. = 0
my_top   = 0
my_end   = 0
prv_ptr  = 0
!my_ptr  = 0

Re: Pointers, arrays and dynamic lists on Rexx

PostPosted: Mon May 31, 2010 11:01 pm
by hakghen
Hey there guys! Thanks for the docs and example! I'm studying them right now.

As soon as I finish the work I'm supposed to do to my university I'll post the result here ;)

Thanks once again!!!