Results 1 to 2 of 2

Thread: Introduction to Eval module

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Introduction to Eval module

    Eval module is one of my preferred modules. This module allows dynamic math functions being evaluated from text strings opening the road of many different options.
    To start with this module here it is just little script using console for output:

    [code=thinbasic]
    USES "CONSOLE" '---We need Console module to write output
    USES "EVAL" '---We need Eval module to evaluate math strings

    DIM t0, t1 AS DOUBLE = TIMER '---Some timing variable
    DIM MyFunction AS STRING '---Will contain math function to eval

    '---Define Y = f(X) ... function
    MyFunction = "y = COS(x) * 10 + SIN(x)"

    '---Tells eval engine to define new 2 variables: x and y
    Eval_SetNumber("x", 0)
    Eval_SetNumber("y", 0)

    '---Define a looper and its max
    DIM Count AS LONG
    DIM MaxCount AS LONG VALUE 50

    FOR Count = -MaxCount to MaxCount
    '---Set X value
    Eval_SetNumber("x", Count)
    '---Eval MyFunction
    Eval(MyFunction)
    '---Write some info output
    CONSOLE_WRITELINE(format$(Count, "0000") & " " & Eval_GetNumber("y"))
    NEXT

    '---Measure the ending time
    t1 = TIMER

    '---Final results
    CONSOLE_WRITELINE("------------------------------------------------------")
    CONSOLE_WRITELINE("Time in seconds for " & str$(MaxCount * 2) & " loops: ")
    CONSOLE_WRITELINE(FORMAT$(t1-t0, "#0.00000"))
    CONSOLE_WRITELINE("------------------------------------------------------")

    '---Wait for a key to stop execution
    CONSOLE_WAITKEY
    [/code]

    More examples will come showing how to link script variable to Eval internal variables.
    Also check about execution speed ...
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Introduction to Eval module

    That eval module is like petr's tbgl module, full of magic that makes wonderful things happen. My time was 0.047 seconds.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Introduction to Dictionary module
    By ErosOlmi in forum Dictionary module
    Replies: 1
    Last Post: 22-04-2007, 09:22

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •