{"id":21016237,"url":"https://github.com/edadma/sprolog","last_synced_at":"2025-03-13T16:45:57.003Z","repository":{"id":26386730,"uuid":"29836211","full_name":"edadma/sprolog","owner":"edadma","description":"Warren Abstract Machine based Prolog interpreter in Scala","archived":false,"fork":false,"pushed_at":"2017-02-13T05:31:32.000Z","size":147,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"0.1","last_synced_at":"2025-01-20T12:09:14.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edadma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-25T23:27:04.000Z","updated_at":"2024-07-11T14:56:26.000Z","dependencies_parsed_at":"2022-09-11T22:40:23.455Z","dependency_job_id":null,"html_url":"https://github.com/edadma/sprolog","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edadma%2Fsprolog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edadma%2Fsprolog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edadma%2Fsprolog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edadma%2Fsprolog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edadma","download_url":"https://codeload.github.com/edadma/sprolog/tar.gz/refs/heads/0.1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243447512,"owners_count":20292448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T10:12:41.119Z","updated_at":"2025-03-13T16:45:56.976Z","avatar_url":"https://github.com/edadma.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"S-Prolog\n========\n\nS-Prolog is a Warren Abstract Machine (WAM) based Prolog interpreter in Scala.  Currently, a large subset of the WAM instruction set is implemented.  There is no tail recursion optimization or procedure indexing for fast rule matching yet.  The specialized optimizing instructions supporting constants, lists and anonymous variables are implemented.  Most of the commonly used built-in predicates are implemented.\n\nThis will aim to be a subset of ISO Prolog including a standard Prolog parser using https://github.com/edadma/rtcep.\n\nHere is an example of what it can do so far.\n\n    val p = Prolog.program( \"\"\"\n\t\t/*\n\t\t * Symbolic differentiation and simplification\n\t\t */\n\t\td( X, X, 1 ).\n\t\td( C, X, 0 ) :- number( C ).\n\t\td( -A, X, -U ) :- d( A, X, U ).\n\t\td( C*A, X, C*U ) :- number( C ), d( A, X, U ).\n\t\td( A + B, X, U + V ) :- d( A, X, U ), d( B, X, V ).\n\t\td( A - B, X, U - V ) :- d( A, X, U ), d( B, X, V ).\n\t\td( A*B, X, B*U + A*V ) :- d( A, X, U ), d( B, X, V ).\n\t\t\n\t\ts( A + B, C ) :- !, s( A, A1 ), s( B, B1 ), op( A1 + B1, C ).\n\t\ts( A - B, C ) :- !, s( A, A1 ), s( B, B1 ), op( A1 - B1, C ).\n\t\ts( A*B, C ) :- !, s( A, A1 ), s( B, B1 ), op( A1*B1, C ).\n\t\ts( X, X ).\n\t\t\n\t\top( A + B, C ) :- number( A ), number( B ), !, C is A + B.\n\t\top( 0 + A, A ) :- !.\n\t\top( A + 0, A ) :- !.\n\t\top( 1*A, A ) :- !.\n\t\top( 0*A, 0 ) :- !.\n\t\top( A*1, A ) :- !.\n\t\top( A*0, 0 ) :- !.\n\t\top( A - 0, A ) :- !.\n\t\top( A - A, 0 ) :- !.\n\t\top( A + A, 2*A ) :- !.\n\t\top( X, X ).\n\t\t\n\t\tdn( -(-(A)), B ) :- !, dn( A, B ).\n\t\tdn( -(A + B), U + V ) :- !, dn( -(A), U ), dn( -(B), V ).\n\t\tdn( -(A*B), U*V ) :- !, dn( -(A), U ), dn( -(B), V ).\n\t\tdn( A + B, U + V ) :- !, dn( A, U ), dn( B, V ).\n\t\tdn( A*B, U*V ) :- !, dn( A, U ), dn( B, V ).\n\t\tdn( A, A ).\n\t\t\n\t\tsimp( X, Y ) :- dn( X, A ), s( A, Y ).\n\t\t\n\t\t/*\n\t\t * Quicksort\n\t\t */\n\t\tpivoting( H, [], [], [] ).\n\t\tpivoting( H, [X|T], [X|L], G ) :- X \u003e= H, pivoting( H, T, L, G ).\n\t\tpivoting( H, [X|T], L, [X|G] ) :- X \u003c H, pivoting( H, T, L, G ).\n\t\t\n\t\tquick_sort( List, Sorted ) :- q_sort( List, [], Sorted ).\n\t\t\n\t\tq_sort( [], Acc, Acc ).\n\t\tq_sort( [H|T], Acc, Sorted ):-\n\t\t\tpivoting( H, T, L1, L2 ),\n\t\t\tq_sort( L1, Acc, Sorted1 ), q_sort( L2, [H|Sorted1], Sorted ).\n        \"\"\" )\n\n    println( Prolog.query(p, \"d( x*x - 2, x, X ), simp( X, Y ).\") )\n    println\n    println( Prolog.query(p, \"quick_sort( [7, 4, 6, 5, 2, 9], L ).\") )\n\noutput:\n\n    X = x*1 + x*1 - 0, Y = 2*x\n\n    L = [2, 4, 5, 6, 7, 9]\n    \n\n## License\n\nS-Prolog is distributed under the MIT License, meaning that you are free to use it in your free or proprietary software.\n\n\n## Usage\n\nUse the following elements to use S-Prolog in your Maven project:\n\n\t\u003crepository\u003e\n\t\t\u003cid\u003ehyperreal\u003c/id\u003e\n\t\t\u003curl\u003ehttps://dl.bintray.com/edadma/maven\u003c/url\u003e\n\t\u003c/repository\u003e\n\n\t\u003cdependency\u003e\n\t\t\u003cgroupId\u003exyz.hyperreal\u003c/groupId\u003e\n\t\t\u003cartifactId\u003esprolog\u003c/artifactId\u003e\n\t\t\u003cversion\u003e0.1\u003c/version\u003e\n\t\u003c/dependency\u003e\n\nAdd the following to your `build.sbt` file to use S-Prolog in your SBT project:\n\n\tresolvers += \"Hyperreal Repository\" at \"https://dl.bintray.com/edadma/maven\"\n\n\tlibraryDependencies += \"xyz.hyperreal\" %% \"sprolog\" % \"0.1\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedadma%2Fsprolog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedadma%2Fsprolog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedadma%2Fsprolog/lists"}