--- title: "Using DEF FN and FN" type: "article" slug: "using-def-fn-and-fn" url: "http://localhost/article/using-def-fn-and-fn/" markdown_url: "http://localhost/article/using-def-fn-and-fn.md" published_at: "2022-10-07T12:25:00+00:00" modified_at: "2026-08-09T11:22:32+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "DEF FN and FN commands define and call functions for math operations, string manipulations, and Boolean logic evaluations in BASIC programming." category: - name: "The Plotter" slug: "the-plotter" taxonomy: "category" url: "http://localhost/category/periodicals/the-plotter/" post_tag: - name: "Best of Timex/Sinclair 2068 Articles and Documents" slug: "ts2068best" taxonomy: "post_tag" url: "http://localhost/tag/ts2068best/" - name: "QL" slug: "ql" taxonomy: "post_tag" url: "http://localhost/tag/ql/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" - name: "Tutorial" slug: "tutorial" taxonomy: "post_tag" url: "http://localhost/tag/tutorial/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" basic: - name: "DEF FN" slug: "def-fn" taxonomy: "basic" url: "http://localhost/basic/def-fn/" - name: "FN" slug: "fn" taxonomy: "basic" url: "http://localhost/basic/fn/" model: - name: "Sinclair QL" slug: "sinclair-ql" taxonomy: "model" url: "http://localhost/model/sinclair-ql/" - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" publication_r: id: 21216 title: "The Plotter" type: "periodical" url: "http://localhost/periodical/the-plotter/" authors: "Bill Jones" authors_r: - name: "Bill Jones" slug: "bill-jones" taxonomy: "indiv" url: "http://localhost/indiv/bill-jones/" volume: "9" issue: "4" issues_articles: - id: 39484 title: "The Plotter v9 n4" type: "issue" url: "http://localhost/issue/the-plotter-v9-n4/" pages: "4" pubdate: "April 1991" archive_link: false --- # Using DEF FN and FN Given are three little example programs that mixes up a brew of ways to use DEF FN and FN. There are zillions of ways that the “DEFine” functions can be used for both math and literal operations. RULES: The command “FN” is used in a line of programming (or in the direct mode). When the “FN” Command is given, “program lines are searched” the DEFined Function, which is expressed somewhere in a program line. The DEF FN expression can be “early or late” in the program lines. AND, an “earlier” DEF EN expression can be used by a “later” expression to solve differential equations. But MATH is but one of many usages of the DEF FN and FN functions. One can use most of the Basic language key words within a DEF FN expression. An example: `100 DEF FN c$()=("yes" AND a>0) +("no" AND a<1). AND a(1)`. This simple Boolean evaluation can be expanded upon to do thousands of selective literal assignments. `PRINT FN c$ ()` solves the function. Sometimes literal explanations are too dense and complicated to get the points across. The best way, I believe, is to give some short and sweet examples. The three short demo programs are given. The first one demos simple math formula solutions. The second demos a bit of string slicing and conversions from literal to numeric. The third is a bit more complicated. Key in the programs and become familiar with the DEF FN and FN logic. Other applications of DEF FN are given in Update Magazine (January 1991 and April 1991). Enjoy! ``` 5 REM Demo of using DEF FN for String Slicing: Conversion from Literal to Numeric, and Math 10 LET a$="1234567890" 20 LET a=VAL FN y$() 30 PRINT a^2 40 PRINT SQR a 500 DEF FN y$()=a$ ( TO 2) ``` ``` 10 REM Demo of math solutions with DEF FN and FN 20 INPUT "Input Circle Radius"; I 30 PRINT "The Cir Area is ";FN a() 40 PRINT "The Diameter is ";FN b() 50 PRINT "The Circumference is ";FN c() 100 DEF FN a()=PI*r^2 110 DEF FN b()=r*2 120 DEF FN C()=2*PI*r ``` ``` 5 REM Demo of DEF FN, FN, READ, DATA, RESTORE, plus a bit of BOOLEAN Logic 10 INPUT "Enter your Age ";a 30 RESTORE (60 AND a<30)+(65 AND a>29 AND a<50)+(70 AND a>49) 60 DATA "Hello Young Squirt" 65 DATA "Watch out for Middle Age Blues" 70 DATA "Enjoy your mellow years" 80 READ a$ 90 PRINT FN b$() 100 DEF FN b$()=a$ 110 GO TO 10 ```