Input from stdin

If you have any questions, remarks, ... if you need help... its here...

Input from stdin

Postby sotolf » 30 Jul 2015 15:59

I'm using oforth on linux (arch linux / ubuntu) and I'm having problems with the input from stdin in oforth ( System.Console askln) It doesn't seem like it recognizes the carriage return, and the pointer goes down to the next line, but I never get returned to the interpreter, (the same happens if I run a program with System.Console askln) am I doing something wrong here? I would really love to be able to use it, since writing an interactive program is hard when it doesn't work. Maybe there is some subtility about it that I haven't understood.
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53

Re: Input from stdin

Postby admin » 30 Jul 2015 16:30

Hi,

Your code is ok and it works on Windows OS.
I don't have access to Linux OS until the end of the week. I will check then and come back to you.

Franck
admin
Administrateur du site
 
Posts: 1
Joined: 06 Feb 2013 08:43

Re: Input from stdin

Postby sotolf » 31 Jul 2015 07:36

Thank you.

I really have to say thanks for the quick reply, and for an awesome language! Oforth is more or less what I wish forth would be to me, it just feels right, the support for objects makes working with strings and collections so much more like what I'm used to, I really like it. It seems like even I would be able to implement factor style combinators in it. It's just so nice to see such a solid well working piece of software, thank you :)
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53

Re: Input from stdin

Postby Franck » 31 Jul 2015 17:35

You're welcome.

If what you call combinators are high order words (words that take a method or a block as parameter), you can find lot of examples into lang package files.
Most are into lang/collect/Collection.of but some are also into other files.

If interested, I can suggest you to open lang.pkg file, which is the package file for lang description (this lang package is loaded at startup) and look at files loaded, using file order listed into this file.
High order words declarations begin into Collection.of file.

Franck
Franck
 
Posts: 144
Joined: 29 Oct 2014 19:01

Re: Input from stdin

Postby sotolf » 01 Aug 2015 20:37

cool :) I'll take a look at those, I'm usually a bit scared of reading libraries, because they tend to go over my head, but it sounds like a good idea.

combinators in factor are probably not needed that often in oforth, because of the support for local variables, but it's how a lot of things are done in factor, I was thinking about it mostly to see if I could do something like it myself for fun though :)

you have for example bi, which takes a value and two blocks, and executes the two blocks on the value

Code: Select all
 3 [ 4 + ] [ 1 + ] bi


which leaves 7 and 4 on the stack. and keep, which copies a value temporarily to the return stack, and puts it back when its off

Code: Select all
 1 2 [ 2 + ] keep


which leaves 1 4 2 on the stack.

It's basically used quite a bit to manage the stack without all the more primitive stack shuffeling words.
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53

Re: Input from stdin

Postby Franck » 02 Aug 2015 09:57

I think you are right. I can't find how these combinators (at least those 2) could be usefull in Oforth.

If needed, bi could be written in Oforth this way :

Code: Select all
: bi(p, q, x) { x q perform x p perform }


Code: Select all
>2 #[ 2 + ] #[ 3 + ] bi .s
[1] (Integer) 5
[2] (Integer) 4
ok
>"aBcDeF" #toUpper #toLower bi + .
ABCDEFabcdef ok
>


And I think it is a good exercice to write them in Oforth. You are right to try to do it.
So I leave "keep" (and others if they exist) to you :)

Franck
Franck
 
Posts: 144
Joined: 29 Oct 2014 19:01

Re: Input from stdin

Postby Franck » 03 Aug 2015 10:16

For #askln problem, I have checked on Linux OS.
There is a bug into #askln method (check for CR instead of LF) : Windows send a CR and Linux send a LF for an end on line.
I will fix this on next version to work on both OS.

Meanwhile, if you want to patch it before next release, it is possible (if Linux only) :
1) Go to lang/resource/Console.of
2) Line 108, into #ask method, change CR into LF.

Franck
Franck
 
Posts: 144
Joined: 29 Oct 2014 19:01

Re: Input from stdin

Postby sotolf » 03 Aug 2015 12:15

Thank you :) That was quick :)

I've been working with taking input from a separate file in the mean time, and that works really well.

I'll check out if I can do that when I get home again.
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53

Re: Input from stdin

Postby sotolf » 04 Aug 2015 06:59

Just tried it out yesterday, and it works perfectly :D Thank you, I'm still having a lot of fun coding easy things still, and let's see whn I get into something a bit more advanced I may post some code here on the forum as well ;) or do some rosetta code stuff, that's where I found oforth, and that's something I'd like to put forward, so that others can also find it, it really is a cool language.
sotolf
 
Posts: 55
Joined: 30 Jul 2015 15:53

Re: Input from stdin

Postby Franck » 04 Aug 2015 21:29

Great.

btw, those combinators are an interesting topic.
If you post some code about them, I think it you be interesting to create a dedicated topic.

Franck
Franck
 
Posts: 144
Joined: 29 Oct 2014 19:01


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron