old book examples lazarus / 61-Beginners ---------------------------------------------------------------------- juanirias · 2016-06-14 00:19 Hi! Please give me a example working... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure bisect  (function f(x:real):real;      x0,x1,xtol:real; maxits:posints;     var root,fatroot:real; var noofits:posints;     var converged:boolean);       { This procedure assumes x0iterating;    converged:=state=withintol;    root:=(x0+x1)/2;    fatroot:=f(root);  noofits:=itcount   end {bisect};          The function must be call using Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i bisect(f,1,2,tol,50,x,fx,its,success)  with the enviroment: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  tol=5e-7;type  posints=1..maxint;var  x,fx:real;  its:points;  success:boolean; function f(x:real):real;begin  f:=x-exp(1/x)end {f}; ---------------------------------------------------------------------- molly · 2016-06-14 05:25 The following leaves you with (highlighted, which i assume are) typo's: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program withtypos; type   TCallFunct=function(x: real): real;  posints=1..maxint; procedure bisect(f:TCallFunct;    x0,x1,xtol:real;maxits:posints;    var root,fatroot:real;var noofits:posints;    var converged:boolean);        { This procedure assumes x0iterating;  converged:=state=withintol;  root:=(x0+x1)/2;  fatroot:=f(root);  noofits:=itcountend {bisect}; const  tol=5e-7;var  x,fx:real;  its:points;  success:boolean; function f(x:real):real;begin  f:=x-exp(1/x)end {f}; begin  bisect(@f,1,2,tol,50,x,fx,its,success);end. ---------------------------------------------------------------------- Graeme · 2016-06-14 10:37 Quote from: molly on June 14, 2016, 07:25:13 amThe following leaves you with (highlighted, which i assume are) typo's: On a different topic....  Wow, I didn't know you can highlight certain lines in a code example. Very useful to know. How did you find that information? ---------------------------------------------------------------------- juanirias · 2016-06-14 16:10 Dear Sir, I cannot compile, this are the errors: Please review: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc "Tbisect.pas"  (in directory: /home/ji/wip/atkinson)Free Pascal Compiler version 2.6.4 [2015/06/17] for x86_64Copyright (c) 1993-2014 by Florian Klaempfl and othersTarget OS: Linux for x86-64Compiling Tbisect.pasTbisect.pas(31,7) Error: Identifier not found "maxitreachead"Tbisect.pas(48,17) Error: Identifier not found "points"Tbisect.pas(48,17) Error: Error in type definitionTbisect.pas(52,36) Error: Call by var for arg no. 8 has to match exactly: Got "" expected "posints"Tbisect.pas(55) Fatal: There were 4 errors compiling module, stoppingFatal: Compilation abortedError: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)Compilation failed. ---------------------------------------------------------------------- molly · 2016-06-14 17:14 Quote from: Graeme on June 14, 2016, 12:37:42 pmOn a different topic....  Wow, I didn't know you can highlight certain lines in a code example. Very useful to know. How did you find that information? Good question :-) I'm used to using it on some other boards where i post. I got the hint that it was available here (if i remember correctly)  from one of rvk's or howardpc's code examples which used it in their code-tags. It seems (e.g. looks like and talks like a duck so must be a duck logic) that the board is using GeShi highlighter mod, in which case the documentation can be found here. ---------------------------------------------------------------------- molly · 2016-06-14 17:23 Quote from: juanirias on June 14, 2016, 06:10:46 pmDear Sir, I cannot compile, this are the errors: Please review: Yes, i already anticipated on those errors by highlighting the lines which contained the typo's  I all went ok, then without typos: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program withoutypos; type   TCallFunct=function(x: real): real;  posints=1..maxint;  procedure bisect(f:TCallFunct;    x0,x1,xtol:real;maxits:posints;    var root,fatroot:real;var noofits:posints;    var converged:boolean);        { This procedure assumes x0iterating;  converged:=state=withintol;  root:=(x0+x1)/2;  fatroot:=f(root);  noofits:=itcountend {bisect}; function f(x:real):real;begin  f:=x-exp(1/x)end {f}; const  tol=5e-7;var  x,fx:real;  its:posints;  success:boolean; begin  bisect(@f,1,2,tol,50,x,fx,its,success);end. Lines 31, and 48 were modified (highlighted again) ---------------------------------------------------------------------- juanirias · 2016-06-14 17:36 Thanks for SOLVED I learn today  please to see the solution add: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i writeln('  x   : ',x:3:10);writeln(' f(x) : ',fx:3:10); ---------------------------------------------------------------------- howardpc · 2016-06-14 17:44 A cleaner code style would be something like this ('real', for instance has different meanings on different platforms and is best avoided): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program BisectCleanedUp; {$R *.res} const  Tol = 5e-7; type  TPosInts = 1..maxint;  TFunction = function(x: single): single;  TState = (stIterating, stWithinTol, stMaxItReached); var  x0, x1, x, fx: single;  its: TPosInts;  success: boolean; function f(x: Single): Single;begin  f:=x-exp(1/x);end; procedure bisect(f: TFunction;               x0, x1, xTol: Single;                 maxits: TPosInts;               out root, fatroot: Single;                 out noofits: TPosInts;                 out converged: boolean);var  x, fx, f0: Single;  itcount: integer = 0;  state: TState = stIterating;begin  Assert(x0 stIterating);  converged:=(state = stWithinTol);  root:=(x0+x1)/2;  fatroot:=f(root);  noofits:=itcount; end; begin  x0:=1;  x1:=2;  bisect(@f, x0, x1, Tol, 50, x, fx, its, success);  WriteLn('x0=',x0:2:2,', x1=',x1:2:2,', x=',x:2:2,', fx=',fx:2:2,', its=',its,', success=',success);end. ---------------------------------------------------------------------- juanirias · 2016-06-14 18:06 Dear Sir I'm under fedora linux; and have this error: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Tbisect.pas(26,26) Fatal: Syntax error, ":" expected but "identifier ROOT" found How can I fix it? regards, JUAN ---------------------------------------------------------------------- howardpc · 2016-06-14 18:22 Syntax errors usually indicate typos. Check your punctuation carefully. You could try changing the procedure signature to this (though I don't know if it will make any difference): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure bisect(f: TFunction;                 x0, x1, xTol: Single;               maxits: TPosInts;                 out root: Single;               out fatroot: Single;                 out noofits: TPosInts;               out converged: boolean); ---------------------------------------------------------------------- juanirias · 2016-06-14 19:03 Please see the attachment ---------------------------------------------------------------------- howardpc · 2016-06-14 21:54 I have no experience with using Geany. The identical code when run in the Lazarus IDE compiles flawlessly. Perhaps someone familiar with Geany's defaults can explain what differs between the two environments. Note that this is a Lazarus forum. Respondents will assume you are using Lazarus unless you specifically say otherwise. ---------------------------------------------------------------------- molly · 2016-06-14 22:05 Quote from: howardpc on June 14, 2016, 11:54:19 pmI have no experience with using Geany. Me neither, but since it is a 'simple' editor similar to the editor i use: i had to add mode objfpc (or delphi) in order for the out modifier to work. With the assumption that no additional/out of the ordinary Free Pascal configuration was done. So for OP: add the following at the top just beneath your program declaration: Code: [Select]{$MODE OBJFPC} and see if that helps ? ---------------------------------------------------------------------- juanirias · 2016-06-14 22:12 Its help thanks