import for iterator|crack language

24 views
Skip to first unread message

limor cohen

unread,
Mar 4, 2014, 1:43:40 PM3/4/14
to crack-l...@googlegroups.com
hi,
which import should I use for iterator in crack programming language?

Michael Muller

unread,
Mar 4, 2014, 1:47:22 PM3/4/14
to crack-lang-dev
See the "iteration protocol" - http://www.mindhog.net/~mmuller/projects/crack/Manual-0.9.html#the_iteration_protocol

In short, containers usually have a iter() method that returns an iterator object which has elem() and next() methods.  The for statement hides this for you.

You can also do 'for (i :on collection)' if you want 'i' to be the iterator rather than the element.


On Tue, Mar 4, 2014 at 1:43 PM, limor cohen <limor...@gmail.com> wrote:
hi,
which import should I use for iterator in crack programming language?

--
You received this message because you are subscribed to the Google Groups "crack-lang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crack-lang-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

limor cohen

unread,
Mar 4, 2014, 2:00:11 PM3/4/14
to crack-l...@googlegroups.com
ok..
but when i tried to define an "Iterator I", i got this message:"ParseError:: Unknown identifier Iterator".

בתאריך יום שלישי, 4 במרץ 2014 10:47:22 UTC-8, מאת mindhog:

limor cohen

unread,
Mar 4, 2014, 2:40:31 PM3/4/14
to crack-l...@googlegroups.com
help?

בתאריך יום שלישי, 4 במרץ 2014 11:00:11 UTC-8, מאת limor cohen:

Michael Muller

unread,
Mar 4, 2014, 3:20:14 PM3/4/14
to crack-lang-dev
On Tue, Mar 4, 2014 at 2:40 PM, limor cohen <limor...@gmail.com> wrote:
help?

בתאריך יום שלישי, 4 במרץ 2014 11:00:11 UTC-8, מאת limor cohen:
ok..
but when i tried to define an "Iterator I", i got this message:"ParseError:: Unknown identifier Iterator".

There's no general iterator class in Crack.  Each container type has its own iterator type.

Also, due to a current "wart" in the language, you can't access the types directoy :-) So, for example, "Array[int].ArrayIter i" won't work.

You typically don't care, though because you can define a new iterator variable like this:

  Array[int] arr = {};
  i := arr.iter();


If you really want access to the iterator type, what you _can_ do is access them with the typeof() operator and then alias them: 

  alias IntArrayIter = typeof(Array[int]().iter();

  IntArrayIter i;
  i = arr.iter();

limor cohen

unread,
Mar 4, 2014, 6:02:37 PM3/4/14
to crack-l...@googlegroups.com
Okay .. if I want to move the directory with the iterator, how do I do it?
Is that possible?

בתאריך יום שלישי, 4 במרץ 2014 12:20:14 UTC-8, מאת mindhog:

limor cohen

unread,
Mar 5, 2014, 2:23:30 AM3/5/14
to crack-l...@googlegroups.com
help?

בתאריך יום שלישי, 4 במרץ 2014 15:02:37 UTC-8, מאת limor cohen:

Michael Muller

unread,
Mar 5, 2014, 8:50:15 AM3/5/14
to limor cohen, crack-l...@googlegroups.com

limor cohen wrote:
> Okay .. if I want to move the directory with the iterator, how do I do it?
> Is that possible?

I'm not sure I understand the question. Are you iterating over a
crack.fs.Path object? If so, we don't currently have a wrapper for the
rename() function, which is what you would need to move a directory under
unix.

Your options are:

1) Add the rename() function to crack/runtime/Init.cc, then add a rename()
wrapper to crack.fs.Path and its implementations. (Then send us the patch and
indicate your willingness to have it distributed under a BSD 2 license with
the rest of Crack :-)
2) Use crack.fs.process to shell out to 'mv'
3) directly import rename from the shared library where it is defined:
import "libc.so.6" rename;
void rename(byteptr s, byteptr d);

rename(CString(file1).buffer, CString(file2r).buffer);

If you're using arbitrary strings, be sure to wrap them in
crack.lang.CString, as these are guaranteed to be null terminated while
arbitrary strings are not.

>
> בתאריך יום שלישי, 4 במרץ 2014 12:20:14 UTC-8, מאת mindhog:
> >
> >
> >
> >
> > On Tue, Mar 4, 2014 at 2:40 PM, limor cohen <limor...@gmail.com<javascript:>
> >> email to crack-lang-de...@googlegroups.com <javascript:>.
> >> For more options, visit https://groups.google.com/groups/opt_out.
> >>
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups "crack-lang-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to crack-lang-de...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>


=============================================================================
michaelMuller = mmu...@enduden.com | http://www.mindhog.net/~mmuller
-----------------------------------------------------------------------------
The people can always be brought to the bidding of the leaders. That is easy.
All you have to do is tell them they are being attacked and denounce the
pacifists for lack of patriotism and exposing the country to danger. It works
the same way in any country. - Hermann Goering (Hitler's right-hand man)
=============================================================================
Reply all
Reply to author
Forward
0 new messages