Structures and routines

Examples are from under OS X. If the code here wants to be copy/pasted to the World prompt, turn auto-brackets off with Ctrl-A in World.

The libc routine gettimeofday returns the current calendar time as the elapsed time since the epoch. It takes pointers to two structures as arguments and fill those structures with data.

First libc needs to be loaded:

    w> libc: load/library %/usr/lib/libc.dylib

Then the structures and routine are defined:

    timeval: struct [
        slong sec
        sint32 usec
    ] none

    timezone: struct [
        sint minuteswest
        sint dsttime
    ] none

    gettimeofday: routine [
        [typecheck]
        libc "gettimeofday" [
            tp [struct!] pointer
            tzp [struct!] pointer
        ]
        sint
    ]

gettimeofday can now be called:

    w> gettimeofday timeval timezone
    == 0


timeval and timezone then holds the data. The routine localtime_r takes time and a struct tm as arguments and fill the structure with data:

    tm: struct [
        sint sec
        sint min
        sint hour
        sint mday
        sint mon
        sint year
        sint wday
        sint yday
        sint isdst
        slong gmtoff
        pointer zone
    ] none

    localtime-r: routine [
        [typecheck]
        libc "localtime_r" [
            time [struct!] pointer
            resultp [struct!] pointer
        ]
        pointer handle!
    ]

The time argument is a pointer to a slong holding the seconds. But that's the first variable in the timeval structure, so we can just pass that:

    w> localtime-r timeval tm

Now tm is filled with data, and we can e.g. get the day of the year:

    w> tm/yday
    == 353


There is some freedom in defining structures. C datatype and argument name can be exchanged. It's also possible to give initial values, so these two are the same:

    struct [float f] [1.0]
    struct [f float] [1.0]

Now find some more interesting libraries to integrate with!

33 comments:

  1. Integrates with OpenCOBOL runtime and compile shared modules.

    ReplyDelete
    Replies
    1. IEEE Final Year projects Project Center in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes. Final Year Project Domains for IT

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, project projects for cse. Angular Training

      Delete
  2. That's cool, Brian! I would like World to integrate with lots of other technologies, both World calling others, and others calling into World. The former is possible for example with these routines, the latter is yet to come.

    ReplyDelete
  3. Wow. I had played a bit with Red, but this is also amazing. Just playing with parse and seems very complete.
    I was getting worried about the state of rebol and now there are two excellent projects to take the ideas forward. Keep up the great work and thank you :-)

    ReplyDelete
  4. Very nice. This will help make World a great glue language.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. do you continue developing world? I like it but haven't seen a post for a long time

    ReplyDelete
  7. Yes, World is still being developed, but as I finance the development myself, I had to take time away from the project. A new version is available, so use the "Get World" link at the top to get this. I may put some new blog posts up soon.

    ReplyDelete
  8. Hey there, You have done a fantastic job. I will certainly digg it and personally suggest to my friends. I’m confident they’ll be benefited from this website.
    C Programming Courses in Chennai

    ReplyDelete
  9. I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective. Techno-based information has been fetched in each of your topics. Sure it will enhance and fill the queries of the public needs. Feeling so glad about your article. Thanks…!
    selenium training in chennai
    selenium online courses best selenium online training
    selenium testing training
    selenium classes

    ReplyDelete
  10. Good job! Fruitful article. I like this very much. It is very useful for my research. It shows your interest in this topic very well. I hope you will post some more information about the software. Please keep sharing!!
    SEO Training in Chennai
    SEO Training in Bangalore
    SEO Training in Coimbatore
    SEO Training in Madurai
    SEO Course in Chennai
    SEO Course in Chennai
    SEO Course in Bangalore
    SEO Course in Coimbatore

    ReplyDelete
  11. Nice blog, it’s so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us. Keep Sharing.
    Digital Marketing Course In Kolkata
    Web Design Course In Kolkata

    ReplyDelete
  12. Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...Well written article share more
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  13. First and foremost, make sure both parents are on the same page and respond in similar ways to poor behavior, implementing the same structure and discipline for specific behaviors in www.floorrefinishingcincinnati.com/

    ReplyDelete
  14. Movie-watching websites that are more than movie-watching websites Because we are the number 1 free movie site in Thailand for a long time, including new movies, Thai movies, Western movies, Asian movies, we have all kinds of ways for you Including new series Full of all stories without interstitial ads to keep annoying anymore. One place sa-movie.com.

    Android and IOS operating systems. Watch online movies, Thai movies, Western movies, Asian movies, Cartoon movies, Netflix Movie, Action Movies, Comedy Movies, Crime Movies, Drama Movies, Horror Movies, Adventure Movies, Crash Movies and still have many new movies to watch. You can watch for free anytime, anywhere 24 hours a day at see4k.com.


    GangManga read manga, read manga, read manga online for free, fast loading, clear images in HD quality, all titles, anywhere, anytime, on mobile, tablet, computer. Android and IOS operating systems. Read top comics, action dramas, comedy, adventure, horror and manga. New coming every day to watch many more. Can be read for free anytime anywhere 24 hours a day at gangmanga.com..

    It is no secret that football is among the most popular and widely watched sports. Everybody who likes football tries to find the best platform for free soccer streaming. So, what are the best free sports streaming sites? We are going to answer this question. On this page, you can find a detailed overview of the most widespread soccer streaming websites. Keep on reading and make the best choice for you live24th.me.

    ReplyDelete
  15. With special privileges and services, UEFA BET offers opportunities for small capitalists. Together ufa with the best websites that collect the most games With a minimum deposit starting from just 100 baht, you are ready to enjoy the fun with a complete range of betting that is available within the website

    ufabet , our one another option We are a direct website, not through an agent, where customers can have great confidence without deception The best of online betting sites is that our Ufa will give you the best price

    หาคุณกำลังหาเกมส์ออนไลน์ที่สามารถสร้างรายได้ให้กับคุณ เรามีเกมส์แนะนำ เกมยิงปลา รูปแบบใหม่เล่นง่ายบนมือถือ คาสิโนออนไลน์ บนคอม เล่นได้ทุกอุปกรณ์รองรับทุกเครื่องมือ มีให้เลือกเล่นหลายเกมส์ เล่นได้ทั่วโลกเพราะนี้คือเกมส์ออนไลน์แบบใหม่ เกมยิงปลา

    อีกทั้งเรายังให้บริการ เกมสล็อต ยิงปลา แทงบอลออนไลน์ รองรับทุกการใช้งานในอุปกรณ์ต่าง ๆ HTML5 คอมพิวเตอร์ แท็บเล็ต สมาทโฟน คาสิโนออนไลน์ และมือถือทุกรุ่น เล่นได้ตลอด 24ชม. ไม่ต้อง Downloads เกมส์ให้ยุ่งยาก ด้วยระบบที่เสถียรที่สุดในประเทศไทย

    ReplyDelete
  16. one fast brownIn case you are looking for a good site, UFA, UEFA Bet casino site. Which can be played as a thorough answer, in a position to answer Quality and Performance It's ideal to get a great deal of the issues. It can be something very punching and fascinating. Excellently, the items that UFABET football betting is absolutely nothing even with the practical experience of quality. Plus accessibility that are able to see final results It's a model that is very sharp and also different. Full of performance of creating wealth Attractiveness With the most beneficial opportunities it is quite nothing You will find opportunities and also probabilities for making profits. Quality and also somewhat diverse For people who have come to make use of the service excellently fox
    บาคาร่า
    สล็อต
    ufa
    แทงบอล

    ReplyDelete